BookmarkSubscribeRSS Feed
Anand
Calcite | Level 5

Can anybody help me to convert EPOCH date to human redable date format ?

for example epoch date 1409071482460 should look like 8/26/2014.

Thanks

Anand

6 REPLIES 6
Kurt_Bremser
Super User

This is a short program I wrote to show the time and date of a UNIX timestamp (helps me to determine if someone's password has expired etc):

data times (keep=x date time);

x = 1398435549; * the UNIX timestamp;

days = int(x / 86400);

time = x - days * 86400;

date = '01jan1970'd + days;

format

  date mmddyy10.

  time time5.

;

label

  x = "Timestamp"

  date = "Date"

  time = "Time (GMT)"

;

run;

proc print data=times noobs label;

var x date time;

run;

vfarmak
Quartz | Level 8

Very helpful.

I encountered the same problem while integrating data from Mongo DB to SAS.

jakarman
Barite | Level 11

A more easy way, the epoch and sas datetime type only are different in the choicen point of zero. SAS is using 1 jan1960, the epoch is using 1 jan1970.  Unix time - Wikipedia, the free encyclopedia  - SAS(R) 9.4 Language Reference: Concepts, Third Edition (date time).   The conversion is adjusting the time-measure for the point of zero.  Giving this datetime variable a SAS format you like you can get every lay-out presented.

data times2;
x = 1398435549; * the UNIX timestamp;
datetm=x+"01jan1970 0:0:0"dt ;
Format datetm datetime. ;
run;

proc print;
run;

---->-- ja karman --<-----
data_null__
Jade | Level 19

Could it be that it needs a decimal.

32         GOPTIONS ACCESSIBLE;

33         data _null_;

34            x = 1409071482.460 + '01JAN1970:00:00:00'dt;

35            *should look like 8/26/2014.;

36            put x=datetime25.3;

37            run;

x=26AUG2014:16:44:42.460

jakarman
Barite | Level 11

Yep you are right, http://www.epochconverter.com/ older system 32-bit are based on seconds, newer systems using the "long epoch" are using fields in milliseconds.
IF this "long epoch" is read binary or as decimal to get seconds divide by 1000.   Checked his long number and it is a "long epoch".  26aug2014:16:44:22

Current Millis - convert millis to date and time, live UTC time

---->-- ja karman --<-----

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 10602 views
  • 3 likes
  • 5 in conversation