BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi,

I want to find Epoch milisecond for a list of date at 6:00AM GMT.

I am not sure how to do it and can you please help?

Many thanks,

HHC

https://www.epochconverter.com/ 

Date and time (GMT): Monday, May 31, 2021 6:00:00 AM

Timestamp in milliseconds: 1622440800000


Date and time (GMT): Sunday, May 30, 2021 6:00:00 AM

Timestamp in milliseconds: 1622354400000

 

data have;
input name $ date:mmddyy10.;
format date mmddyy10.;
datalines;
05/31/2021 
05/30/2021
;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can use DHMS() to convert dates into datetimes.

You can subtract 01JAN1970:00:00 and add six hours to change the basis.

Multiple by 1000 to get milliseconds.

data have;
input name :$10. @1 date :mmddyy. expect ;
format date date9. expect 15.;
datalines;
05/31/2021 1622440800000
05/30/2021 1622354400000
;

data want;
  set have;
  datetime = dhms(date,0,0,0);
  base1960 = datetime;
  base1970_6am = datetime-'01JAN1970:00:00'dt + '06:00't ;
  milliseconds=base1970_6am * 1000;
  diff = (expect - milliseconds)/1000;
  format datetime datetime19. base: comma20. milliseconds 15. ;
  format diff tod12.3;
  put (_all_) (=/) / ;
run;  

Results

name=05/31/2021
date=31MAY2021
expect=1622440800000
datetime=31MAY2021:00:00:00
base1960=1,938,038,400
base1970_6am=1,622,440,800
milliseconds=1622440800000
diff=00:00:00.000


name=05/30/2021
date=30MAY2021
expect=1622354400000
datetime=30MAY2021:00:00:00
base1960=1,937,952,000
base1970_6am=1,622,354,400
milliseconds=1622354400000
diff=00:00:00.000

View solution in original post

6 REPLIES 6
hhchenfx
Barite | Level 11

Yes, I think the start date is 1/1/1970 00:00:00.

ChrisHemedinger
Community Manager

This blog post might help. It mostly addresses the other way (converting Unix datetime to SAS), but you get the idea.

 

data have;
	length sasdt 8 epoch 8;
	format epoch 20.;
	sasdt = '31may2021:06:0:0'dt;
	/* subtract 10 years of seconds, multiple by 1000 for milliseconds */
	epoch = (sasdt - 315619200) * 1000;
	put sasdt= epoch=;
	output;

        sasdt = '30may2021:06:0:0'dt;
	epoch = (sasdt - 315619200) * 1000;
	put sasdt= epoch=;
	output;
run;

 Output:

sasdt=1938060000 epoch=1622440800000
sasdt=1937973600 epoch=1622354400000
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
hhchenfx
Barite | Level 11

That helps but it will open to a bigger problem for me.

How to turn date into 'ddmmmyyy:00:00:00' format.

Then I can do the 

epoch = (sasdt - 315619200) * 1000;
Tom
Super User Tom
Super User

You can use DHMS() to convert dates into datetimes.

You can subtract 01JAN1970:00:00 and add six hours to change the basis.

Multiple by 1000 to get milliseconds.

data have;
input name :$10. @1 date :mmddyy. expect ;
format date date9. expect 15.;
datalines;
05/31/2021 1622440800000
05/30/2021 1622354400000
;

data want;
  set have;
  datetime = dhms(date,0,0,0);
  base1960 = datetime;
  base1970_6am = datetime-'01JAN1970:00:00'dt + '06:00't ;
  milliseconds=base1970_6am * 1000;
  diff = (expect - milliseconds)/1000;
  format datetime datetime19. base: comma20. milliseconds 15. ;
  format diff tod12.3;
  put (_all_) (=/) / ;
run;  

Results

name=05/31/2021
date=31MAY2021
expect=1622440800000
datetime=31MAY2021:00:00:00
base1960=1,938,038,400
base1970_6am=1,622,440,800
milliseconds=1622440800000
diff=00:00:00.000


name=05/30/2021
date=30MAY2021
expect=1622354400000
datetime=30MAY2021:00:00:00
base1960=1,937,952,000
base1970_6am=1,622,354,400
milliseconds=1622354400000
diff=00:00:00.000
hhchenfx
Barite | Level 11

Thank you Eveyrone for helping.

HHC

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 733 views
  • 2 likes
  • 4 in conversation