Home » SQL & PL/SQL » SQL & PL/SQL » How to return sysdate in required format?
How to return sysdate in required format? [message #305486] Tue, 11 March 2008 00:18 Go to next message
hedonist123
Messages: 119
Registered: August 2007
Senior Member
I wish to retrieve sysdate in the form:

03/22/2008 02:35:54 PM or
03/22/2008 02:35:54 AM

I guess we can return the above without AM/PM using the below

TO_CHAR(SYSDATE, 'MM/DD/YYYY HH:MI:SS')

How do I include AM or PM?

Thanks,

Sharath
Re: How to return sysdate in required format? [message #305489 is a reply to message #305486] Tue, 11 March 2008 00:23 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
by adding either AM or PM

TO_CHAR(SYSDATE, 'MM/DD/YYYY HH:MI:SS AM')

regards,
Re: How to return sysdate in required format? [message #305490 is a reply to message #305489] Tue, 11 March 2008 00:28 Go to previous messageGo to next message
hedonist123
Messages: 119
Registered: August 2007
Senior Member
Hi Dhanajay,

I understand what you are saying, but the time might vary and I want it to dynamically show AM//PM depending on the time of the day.
Re: How to return sysdate in required format? [message #305491 is a reply to message #305490] Tue, 11 March 2008 00:30 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9104
Registered: November 2002
Location: California, USA
Senior Member
It does that. It does not matter whether you use AM or PM, it causes it to select the proper one.

1* select to_char (sysdate, 'MM/DD/YYYY HH:MI:SS PM') from dual
SCOTT@orcl_11g> /

TO_CHAR(SYSDATE,'MM/DD
----------------------
03/10/2008 10:28:23 PM

SCOTT@orcl_11g> ed
Wrote file afiedt.buf

1* select to_char (sysdate, 'MM/DD/YYYY HH:MI:SS AM') from dual
SCOTT@orcl_11g> /

TO_CHAR(SYSDATE,'MM/DD
----------------------
03/10/2008 10:28:30 PM

SCOTT@orcl_11g>
Re: How to return sysdate in required format? [message #305492 is a reply to message #305491] Tue, 11 March 2008 00:35 Go to previous message
hedonist123
Messages: 119
Registered: August 2007
Senior Member
Oh really!

Thanks so much Barbara.
Previous Topic: How to Splilit The String Into Single Column using Comma As Delimiter ?
Next Topic: PLS-00103
Goto Forum:
  


Current Time: Sat Feb 15 08:40:01 CST 2025