JB_
JB_

Reputation: 23

oracle sql convert time from timestamp to hhmm

I hope you can help

I am trying to extract the time from a timestamp in this format HHMM in Oracle SQL

I'm currently using this statement

to_number(to_char(g.start_time,'hh24mi'))

It works to a certain extent, but times from 00:00 - 09:59 don't appear as i would like it to do.

For example 00:00 is currently being extracted a single 0 but I need it in four digits 0000 same with 09:59 appears as 959 but I would like it as 0959

do you have any suggestions

Thanking you in advance

Upvotes: 0

Views: 691

Answers (2)

Just don't try to convert it to a number since number will ignore any leading 0. Just use to_char()

to_char(g.start_time,'hh24mi')

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269913

If you need four digits, leave it as a string:

to_char(g.start_time, 'hh24mi')

Numbers don't care about leading zeros.

Upvotes: 0

Related Questions