BookmarkSubscribeRSS Feed
sdang
Quartz | Level 8

I have a column, TimePlayed, and its value is in second.  How do I convert that to hours.  I used the function HOUR but I don't it give me the correct value.

Capture.PNG

Furthermore ,I have two columns indicating the start time and end time if there is any way to get hours played.

Capture.PNG

4 REPLIES 4
ballardw
Super User

If timeplayed is in seconds then code:

hoursplayed = timeplayed/ 3600;

Do you need whole hours or fractions?

The HOUR function returns the value of the hour portion of a datetime or time variable. For your first example of StartTime the hour function would return 16.

You can use the function INTCK with two datetime variables to return the number of hour intervals but may not provide what your are looking for if you want fractions of an hour.

sdang
Quartz | Level 8

Thank you, it helps.

TomKari
Onyx | Level 15

Or if you just want to see the number of seconds as the number of hours, use the time8. format on the number of seconds.

Reeza
Super User

And if both of your variables are datetime you can subtract them to get a duration of time played which would be in seconds.

duration=end_time-start_time;

format duration time8.;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1013 views
  • 9 likes
  • 4 in conversation