DATA Step, Macro, Functions and more

convert date and time IST to EST

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

convert date and time IST to EST

[ Edited ]

 

Hi ,I want to convert Date_time character variable(IST) to EST (date and time format) .please help me.

 

original_datetime_istDate_time
28/12/20163:06:3628DEC2016/3:06:36
11/11/201619:56:3511NOV2016/19:56:35
11/11/201619:55:5811NOV2016/19:55:58
11/11/201619:53:2511NOV2016/19:53:25
11/11/201619:55:2611NOV2016/19:55:26
11/11/201619:51:5311NOV2016/19:51:53
11/11/201619:52:2511NOV2016/19:52:25
16/11/201614:00:5616NOV2016/14:00:56
16/11/201613:25:0216NOV2016/13:25:02
16/11/201615:23:5416NOV2016/15:23:54
16/11/201614:00:1816NOV2016/14:00:18
16/11/201613:08:5516NOV2016/13:08:55
16/11/201616:21:3616NOV2016/16:21:36

 

Thanks,

Siva

 


Accepted Solutions
Solution
‎03-29-2017 07:15 AM
Super User
Posts: 6,963

Re: convert date and time IST to EST

Well, IST is UTC+5:30, while ET (or EST) is UTC-5, so we have to subtract 10:30 from IST time to get the correct timestamp for ET:

data want;
input date_time :$20.;
dt_time = input(date_time,datetime20.);
format dt_time e8601dt20.;
dt_time = dt_time - '10:30:00't;
cards;
28DEC2016/3:06:36
11NOV2016/19:56:35
11NOV2016/19:55:58
11NOV2016/19:53:25
11NOV2016/19:55:26
11NOV2016/19:51:53
11NOV2016/19:52:25
16NOV2016/14:00:56
16NOV2016/13:25:02
16NOV2016/15:23:54
16NOV2016/14:00:18
16NOV2016/13:08:55
16NOV2016/16:21:36
;
run;

You now have a datetime value for Eastern Time, and can use datepart() and timepart() to extract the ET date and time values from that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,963

Re: convert date and time IST to EST

Do

data want;
set have;
original_date = datepart(input(date_time,datetime20.));
time_ist = timepart(input(date_time,datetime20.));
format
  original_date ddmmyy10.
  time_ist time8.
;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 55

Re: convert date and time IST to EST

Thanks sir.

Contributor
Posts: 55

Re: convert date and time IST to EST

Hi KurtBremser, I want both variable (original_date) and (time_ist) should be concatenated in new column (Date_time) and also convert into EST format
Super User
Posts: 6,963

Re: convert date and time IST to EST

Consulting wikipedia, the only date/time-related uses of the acronym EST are Eastern Standard Time and European Summer Time. Do you want to factor in a timezone?

 

Otherwise describe how the final variable should be formatted. When dealing with such values, it's usually best to keep the value as a true SAS datetime value (seconds from 1960-01-01T00:00:00) and use an appropriate format (you can even create a custom one yourself).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 55

Re: convert date and time IST to EST

original_datetime_ist
28/12/20163:06:36

 

Here original date is 28/12/2016 and ist time is 3:06:36 which is Indian Standard Time (IST), I want to convert it to 27/12/2016 and 17:06:36 Estern Standard Time (EST (USA/Canada)).

 

Solution
‎03-29-2017 07:15 AM
Super User
Posts: 6,963

Re: convert date and time IST to EST

Well, IST is UTC+5:30, while ET (or EST) is UTC-5, so we have to subtract 10:30 from IST time to get the correct timestamp for ET:

data want;
input date_time :$20.;
dt_time = input(date_time,datetime20.);
format dt_time e8601dt20.;
dt_time = dt_time - '10:30:00't;
cards;
28DEC2016/3:06:36
11NOV2016/19:56:35
11NOV2016/19:55:58
11NOV2016/19:53:25
11NOV2016/19:55:26
11NOV2016/19:51:53
11NOV2016/19:52:25
16NOV2016/14:00:56
16NOV2016/13:25:02
16NOV2016/15:23:54
16NOV2016/14:00:18
16NOV2016/13:08:55
16NOV2016/16:21:36
;
run;

You now have a datetime value for Eastern Time, and can use datepart() and timepart() to extract the ET date and time values from that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 55

Re: convert date and time IST to EST

Thank you very much for your time
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 248 views
  • 1 like
  • 2 in conversation