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
;
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
So you want the count of milliseconds, starting at 197-01-01T00:00:00, for 06.00:00 on any given date?
Yes, I think the start date is 1/1/1970 00:00:00.
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
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;
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
Thank you Eveyrone for helping.
HHC
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.