cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
d_barnett
Level IV

Unix Timestamp to Real Date & time

I extract data from a database and part of this is a "start time" for a process. The main problem with this is that it is in UNIX format so therefore returns a 10 digit number, I know that the formula for converting this to actual date and time is as follows

( taken from Excel)

=CELL/(60*60*24)+"1/1/1970"

so changing a column in JMP should be straightforward but I can't seem to do it. The (60*60*24) is easy but what format do I have to set the +"1/1/1970" to to make this work?

I have attached a data table that contains some dates from the past 6ish years as an example. My feeling is that this might have been asked before but I can't see anything that relates to it.

Regards


David

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Unix Timestamp to Real Date & time

The UNIX date is the number of seconds since midnight, January 1, 1970.

 

JMP stores dates as the number of seconds since midnight, January 1, 1904.

 

So, we just need to add the JMP date value for January 1, 1970 to the Unix date value. You can use the Date DMY() function to do this:

 

10238_JMPScreenSnapz001.png

 

-Jeff

-Jeff

View solution in original post

15 REPLIES 15
Craige_Hales
Super User

Re: Unix Timestamp to Real Date & time

try 1jan1970 without any quotation marks. 

format( 1jan1970+1445432452, "mdy" )

"10/21/2015"

(That's today, for future reference.  I got Epoch Converter - Unix Timestamp Converter to give me the Unix time for today: 1445432452 )


adding 1jan1970 works because the Unix time for 1jan1970 is zero.  And because JMP and Unix are both counting in seconds.


Be careful, I've seen some discussion about when the Unix epoch really began: Unix time - Wikipedia, the free encyclopedia says


The first edition Unix Programmer's Manual dated 3 November 1971 defines the Unix time as "the time since 00:00:00, 1 January 1971, measured in sixtieths of a second".[5]

The User Manual also commented that "the chronologically-minded user will note that 232 sixtieths of a second is only about 2.5 years". Because of this limited range, the epoch was redefined more than once,[citation needed] before the rate was changed to 1 Hz and the epoch was set to its present value of 1 January 1970 00:00:00 UTC. This yielded a range of about 136 years, though with more than half the range in the past (see discussion of signedness above).

Craige
UersK
Level III

Re: Unix Timestamp to Real Date & time

Thanks!

Jeff_Perkinson
Community Manager Community Manager

Re: Unix Timestamp to Real Date & time

The UNIX date is the number of seconds since midnight, January 1, 1970.

 

JMP stores dates as the number of seconds since midnight, January 1, 1904.

 

So, we just need to add the JMP date value for January 1, 1970 to the Unix date value. You can use the Date DMY() function to do this:

 

10238_JMPScreenSnapz001.png

 

-Jeff

-Jeff
d_barnett
Level IV

Re: Unix Timestamp to Real Date & time

Jeff,

I had noticed January 4, 1904 popping out a number of times and I thought that it was some formatting or calculation error that I had made, this only added to my confusion why I couldn't get this date conversion to work.

thanks for your help

David

NIE-MJ
Level I

Re: Unix Timestamp to Real Date & time

My question is just the opposite, how do I convert real time to Unix timestamps?

jthi
Super User

Re: Unix Timestamp to Real Date & time

I think it should be enough if you remove unix zero time from JMP's datetime as both are in seconds. Hopefully you don't have to touch time zones (The Problem with Time & Timezones - Computerphile (youtube.com))

Names Default To Here(1);

unix_zero = Date MDY(1,1,1970);
date_now = Today();
unix_time = date_now - unix_zero; 
// In Hours() might be helpful if you need timezone conversion

// just to verify that time is correct I'm using Unix Timestamp converter REST API from https://unixtime.co.za/ 
aa = Associative Array();
aa["timestamp"] = unix_time;
request = New HTTP Request(
	URL("https://showcase.api.linx.twenty57.net/UnixTime/fromunix"),
	Method("GET"),
	Query String(aa)
);
data = request << send;
Show(As Date(date_now));
show(data);

 

 

-Jarmo
hogi
Level XII

Re: Unix Timestamp to Real Date & time


@jthi wrote:

... Hopefully you don't have to touch time zones


and if I have to - can Jmp help?

Jeff_Perkinson
Community Manager Community Manager

Re: Unix Timestamp to Real Date & time

There's nothing built-in but usually it's just a matter of adding/subtracting hours (in seconds) from a time.

 

What help do you need?

-Jeff
hogi
Level XII

Re: Unix Timestamp to Real Date & time

Hi @Jeff_Perkinson

something likeTime Zone Conversion.

The video in @jthi 's post shows higher orders of he issue, but even for a "simple" conversion from UTC to German summer/winter time a JSL function could save a lot of time.