简体   繁体   中英

Splitting date and time in Oracle SQl

I have a date time stored in the format mm/dd/yyyy HH24:mi:ss format(example 01/25/2005 10:10:15 PM). Is there any inbuilt function in Oracle SQL to obtain the date value and time value separately?

I cant use the space to split the 2 values because there are 2 spaces(One between date and time and the other between time and AM/PM)

If you have a date , and you want to display the date and time portions separately, use to_char() :

select to_char(mydate, 'yyyy-mm-dd') datepart, to_char(mydate, 'hh24:mi:ss') timepart
from mytable

You control the format of the string representations with the second argument to to_char() .

If you have a string, and you want to split it into two after the first space, then use string functions:

select substr(mystr, 1, instr(mystr, ' ') - 1) datepart, substr(mystr, instr(mystr, ' ') + 1)
from mytable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM