Difference between two times (24hr clock)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Difference between two times (24hr clock)

I am using the following syntax to calculate the minutes between two time variable.

INFTIME = INTCK('MINUTE',INPUT(EXSTTM,TIME8.),INPUT(EXENTM,TIME8.));

 

EXSTTM = 23:48

EXENTM = 00:48

The result is coming out as -1380 but I expect the result to be 60 min obviously. Guess the problem is the end time 00:48 which is the next day. Any suggestion?


Accepted Solutions
Solution
‎12-16-2016 01:50 PM
Trusted Advisor
Posts: 1,131

Re: Difference between two times (24hr clock)

data have ;
EXSTTM = '23:48't;
EXENTM = '00:48't;
if EXENTM lt EXSTTM then duration=('24:00't-EXSTTM)+EXENTM; 
else duration=intck('minute',EXSTTM,EXENTM);
format EXSTTM EXENTM duration time5.;
run;
Thanks,
Jag

View solution in original post


All Replies
Solution
‎12-16-2016 01:50 PM
Trusted Advisor
Posts: 1,131

Re: Difference between two times (24hr clock)

data have ;
EXSTTM = '23:48't;
EXENTM = '00:48't;
if EXENTM lt EXSTTM then duration=('24:00't-EXSTTM)+EXENTM; 
else duration=intck('minute',EXSTTM,EXENTM);
format EXSTTM EXENTM duration time5.;
run;
Thanks,
Jag
Occasional Contributor
Posts: 12

Re: Difference between two times (24hr clock)

Thanks Jag. It worked; I had to do a minor tweak to divide it by 60 as the duration is calculated in seconds and I wanted it to be in minutes.

Kaushik

Super User
Posts: 10,550

Re: Difference between two times (24hr clock)

If you are going to compare times across midnight you will need to incorporate a DATE portion, make a datetime value and then you can use intnx function to return minutes between directly using the 'minute' interval.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 224 views
  • 2 likes
  • 3 in conversation