Search code examples
sqloracle-databasedate-format

How to get the time format I need?


At the moment I get a date in this format:

2019-10-07

That is, it looks like this

TO_CHAR("DATE_BEGIN", 'YYYY-MM-DD')

How to do so in order to receive a date in this format:

Wed Oct 07 2019 00:00:00 GMT 0500

I tried to do so:

 TO_CHAR("DATE_BEGIN", 'DY MON DD YYYY HH24:MI:SS') like '%Wed Aug 28 2019 00:00:00 GMT 0500%'

But something is missing, because it does not work.


Solution

  • I think this is the format you'd like :

    select to_char( systimestamp at time zone 'GMT','Dy Mon dd yyyy hh24:mi:ss TZR') 
      from dual;
    

    or directly use :

    select to_char( systimestamp,'Dy Mon dd yyyy hh24:mi:ss TZR') 
      from dual;
    

    or for your current substitution date use a casting :

    select to_char( cast( date'2019-10-07' as timestamp) at time zone 'GMT',
                          'Dy Mon dd yyyy hh24:mi:ss TZR') 
      from dual;
    

    Demo