Solved

Epoch Timestamp


I'm just trying to get an epoch timestamp. I have a Creator>Attribute Creator>Inspector. I'm using @DateTimeFormat(@DateTimeNow(),%s) but am getting null returned. All other formats work. What would cause this?

Seems like I'm having an issue with epoch time. I'm seeing the same results (null values or rejected features) in other transformers as well, such as the DateTimeFormater. I have tried converting both ways, from and to epoch. Interestingly the 'preview' in the transformer always works. My '%s' format is also auto-recognized as epoch too.

icon

Best answer by lenaatsafe 15 May 2018, 20:05

View original

6 replies

Userlevel 4

It seems like the epoch format requires the time zone, try this:

@Evaluate(@DateTimeFormat(@DateTimeNow(local),%s))

Also look at the @DateTimeFormat documentation, where it specifically says that %s is rejected for regular datetimes.

It seems like the epoch format requires the time zone, try this:

@Evaluate(@DateTimeFormat(@DateTimeNow(local),%s))

Also look at the @DateTimeFormat documentation, where it specifically says that %s is rejected for regular datetimes.

Thanks David. You're right, it needed a defined zone. Works great now.

 

I've read the documentation but can you clarify (or point me to) "%s is rejected for regular datetimes"? I don't see that part and understand what it means.  

 

 

 

Badge
Hi @rqf4v9

 

please take a look at %s description in Date/Time Functions > Format String Flags and Examples > @DateTimeFormat. The doc states:

 

Accepts zoned datetime. Outputs epoch time.
@DateTimeFormat( 19700101000001.234+00:00, %s) = 1.234
@DateTimeFormat( 19700101000001.234, %s) = null
@DateTimeFormat( 19700101000001.234+00:00, %s%z) = null
For unzoned datetime values you could use %Es, however the values will be interpreted as UTC time then.

 

 

Badge
Thanks David. You're right, it needed a defined zone. Works great now.

 

I've read the documentation but can you clarify (or point me to) "%s is rejected for regular datetimes"? I don't see that part and understand what it means.  

 

 

 

Hi @rqf4v9

 

please take a look at %s description in Date/Time Functions > Format String Flags and Examples > @DateTimeFormat. The doc states:

 

Accepts zoned datetime. Outputs epoch time.
@DateTimeFormat( 19700101000001.234+00:00, %s) = 1.234
@DateTimeFormat( 19700101000001.234, %s) = null
@DateTimeFormat( 19700101000001.234+00:00, %s%z) = null
For unzoned datetime values you could use %Es, however the values will be interpreted as UTC time then.

 

 

Hi @rqf4v9

 

please take a look at %s description in Date/Time Functions > Format String Flags and Examples > @DateTimeFormat. The doc states:

 

Accepts zoned datetime. Outputs epoch time.
@DateTimeFormat( 19700101000001.234+00:00, %s) = 1.234
@DateTimeFormat( 19700101000001.234, %s) = null
@DateTimeFormat( 19700101000001.234+00:00, %s%z) = null
For unzoned datetime values you could use %Es, however the values will be interpreted as UTC time then.

 

 

 

Ah, I see. Thank you.
Userlevel 4
Thanks David. You're right, it needed a defined zone. Works great now.

 

I've read the documentation but can you clarify (or point me to) "%s is rejected for regular datetimes"? I don't see that part and understand what it means.

 

 

 

I agree it's not easy to find and it's worded a bit strange... You have to scroll down almost half the page an expand the "@DateTimeFormat" header, where it's documented near the of that section.

 

My interpretation of that phrase is that %s is rejected as a format flag if the input is a regular datetime, as opposed to a datetime with timezone. Feel free to suggest that Safe make this clearer :-)

Reply