Help using Base SAS procedures

Date/Time Difference

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Date/Time Difference

 Hi Community!

 

I am having a difficult time converting Date/Time differences into HH:MM. I want to know how many hours and minutes are between two dates. For instance:

 

EVENT_CAPTURED_DT_SENT        EVENT_CAPTURED_DT_OPEN

02Feb2018 17:31:15.00                     01Mar2018 3:40:41.00


I need the output to express the difference in time as.....354:15 (example of HH:MM)

 

I am currently using the HMS function, but only giving me the difference in time and not the difference between date/time.


Accepted Solutions
Solution
‎03-27-2018 08:37 AM
Super User
Posts: 6,752

Re: Date/Time Difference

Why not just compute the number of hours?  (You would have 341.25 instead of 341:15)

 

It's easy to obtain, and easy to use in computations down the road:

 

duration_hours = (event_captured_dt_open - event_captured_dt_sent) / 3600;

View solution in original post


All Replies
Solution
‎03-27-2018 08:37 AM
Super User
Posts: 6,752

Re: Date/Time Difference

Why not just compute the number of hours?  (You would have 341.25 instead of 341:15)

 

It's easy to obtain, and easy to use in computations down the road:

 

duration_hours = (event_captured_dt_open - event_captured_dt_sent) / 3600;

Esteemed Advisor
Posts: 5,521

Re: Date/Time Difference

the HHMM. format does it for you:

 

data test;
sent_dt = '02Feb2018 17:31:15.00'dt;
open_dt = '01Mar2018 3:40:41.00'dt;
interval = open_dt - sent_dt;
format interval hhmm8.;
run;

proc print; run;
PG
☑ This topic is solved.

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

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