I have to select the value 2019-03-25 from a date column of a table but in the following format:
2019-03-25T00:00:00.000+02:00
Hon can I get it?
Oracle 10g
Thanks!
Join Stack Overflow to learn, share knowledge, and build your career.
The date
datatype does not store milliseconds and timezone information, so I undertand your question as how to format a date
to the target forma, with fixed values for milliseconds and timezone.
If so, you can use to_char()
like so:
to_char(mycol, 'yyyy-mm-dd"T"hh24:mi:ss".000+2:00"')
You can CAST
your DATE
to a TIMESTAMP
and then use FROM_TZ
to set the time zone and then format it to your requirements using TO_CHAR
:
SELECT TO_CHAR(
FROM_TZ( CAST( your_date AS TIMESTAMP ), '+02:00' ),
'YYYY-MM-DD"T"HH24:MI:SS.FF3TZH:TZM'
) AS formatted_date
FROM your_table;
Which, for your sample data:
CREATE TABLE your_table ( your_date ) AS
SELECT DATE '2019-03-25' FROM DUAL
Outputs:
| FORMATTED_DATE | | :---------------------------- | | 2019-03-25T00:00:00.000+02:00 |
db<>fiddle here
We can not store timezone information in db that's why we can simply use below format,
select to_char(sysdate,'YYYY-MM-DD')||'T'||to_char(sysdate,'HH24:MI:SS') from dual
date
datatype has no milliseconds and no timezone. Do you want to force constant values? – GMB Jun 18 '20 at 9:04