Skip to main content

I'm trying to format a human readable date time and I want to include the seconds but nano seconds are a bit much.

 

As far as I can tell there is no date time flag which is just seconds without the fractional seconds so it seems like you need to remove them with a non-datetime tool. Am I missing something?

 

Date times were created using the DateTimeNow function.

It is strange that the documentation refers to "%S" as "Two digit seconds" in the DateTimeConverter but includes all the fractional seconds too. One way could be to stick a StringSearcher with regular expression "^[0-9]+" before the DateTimeConverter and it'll drop the decimals.


How about:

@int(@DateTimeFormat(@Value(datetime),%Y%m%d%H%M%S))

 


How about:

@int(@DateTimeFormat(@Value(datetime),%Y%m%d%H%M%S))

 

You'd have to be careful about the rare case of 59.9 seconds rounding up to an invalid 60 (Edit: not an issue with "int") and any 0 being dropped at the start if it's just a timestamp


You'd have to be careful about the rare case of 59.9 seconds rounding up to an invalid 60 (Edit: not an issue with "int") and any 0 being dropped at the start if it's just a timestamp

The int function truncates rather than rounds.


Hi @virtualcitymatt​ , alternatively, you can also use SubstringExtractor or @Substring function.

@Substring(@DateTimeNow(),0,14)

 

If you would like to round the datetime value, this expression would be possible.

@Substring(@DateTimeAdd(@DateTimeNow(),PT0.5S),0,14)


Hi @virtualcitymatt​ , alternatively, you can also use SubstringExtractor or @Substring function.

@Substring(@DateTimeNow(),0,14)

 

If you would like to round the datetime value, this expression would be possible.

@Substring(@DateTimeAdd(@DateTimeNow(),PT0.5S),0,14)

Thanks - yeah the substring approach was my work around but it seemed like I should have been able to Format it to drop the decimals. Ahh well - I've created an idea for it. It's not the first time I've had to do this.

 

https://community.safe.com/s/bridea/a0r4Q00000I0oS8QAJ/add-an-option-in-datetimeconverter-datetimeformat-to-specify-second-precision


Reply