Converting DateTime Variable to 24-hour numeric time

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

Converting DateTime Variable to 24-hour numeric time

Good afternoon. I'd be thankful for any help you might provide to me.

 

I have a date/time variable with 24-hour time as part of that. What I need to do is to not only strip out the time but to convert it to a simple number. So from 021318 14:30:00 I just need 143000. I can split out the date but each time I try to do the same with the time portion I get 14:30:00 (with special characters). I'd like them to be gone but I can't figure out a good way to do that.

 

Thank you very much.

 

 

 

start_time want
021318 14:30:00 143000
021318 13:10:00 131000
021318 13:30:00 133000
021318 13:37:00 133700
021318 15:30:00 153000
021318 15:30:00 153000
021318 18:30:00 183000
021318 19:00:00 190000

Accepted Solutions
Solution
‎02-15-2018 05:51 PM
Super User
Posts: 12,689

Re: Converting DateTime Variable to 24-hour numeric time

One way to get what I think you are asking for

want= input(compress(put(timepart(start_time),time8.),':'),F6.);

or

want = hour(start_time)*10000+minute(start_time)*100+second(start_time));

 

I do kind of wonder in what way that format is more useful though.

View solution in original post


All Replies
Solution
‎02-15-2018 05:51 PM
Super User
Posts: 12,689

Re: Converting DateTime Variable to 24-hour numeric time

One way to get what I think you are asking for

want= input(compress(put(timepart(start_time),time8.),':'),F6.);

or

want = hour(start_time)*10000+minute(start_time)*100+second(start_time));

 

I do kind of wonder in what way that format is more useful though.

Super User
Posts: 22,525

Re: Converting DateTime Variable to 24-hour numeric time

Use the TIMEPART() function to extract the time. Then you can apply a format to it. Time values are stored as the number of seconds so you could format it various manners or convert it to an actual number. Note that if you keep it as a time and want to calculate duration thats possible but not if you convert it to a number.
Contributor
Posts: 52

Re: Converting DateTime Variable to 24-hour numeric time

Thank you very much. I'm sure there may be other suggestions here that might work as well but this one was so easy even I could make it work!

 

Thank you.

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 150 views
  • 0 likes
  • 3 in conversation