Skip to main content
Solved

Best way to remove fractional seconds in Date Time


virtualcitymatt
Celebrity
Forum|alt.badge.img+35

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.

Best answer by takashi

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)

View original
Did this help you find an answer to your question?

6 replies

spatialexjames
Contributor
Forum|alt.badge.img+10

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.


redgeographics
Celebrity
Forum|alt.badge.img+49

How about:

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

 


spatialexjames
Contributor
Forum|alt.badge.img+10
redgeographics wrote:

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


redgeographics
Celebrity
Forum|alt.badge.img+49
spatialexjames wrote:

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.


takashi
Influencer
  • Best Answer
  • April 4, 2022

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)


virtualcitymatt
Celebrity
Forum|alt.badge.img+35
takashi wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings