Home » SQL & PL/SQL » SQL & PL/SQL » get hour value from sysdate in 24 hour format (Oracle 11.2.0.1.0)
get hour value from sysdate in 24 hour format [message #621719] Sat, 16 August 2014 13:15 Go to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
Hi all,

How do I get hour value from sysdate in 24 hour format (the result should be only number, not varchar value) ?


Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Re: get hour value from sysdate in 24 hour format [message #621720 is a reply to message #621719] Sat, 16 August 2014 13:27 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
use TO_CHAR() & TO_NUMBER()
Re: get hour value from sysdate in 24 hour format [message #621722 is a reply to message #621719] Sat, 16 August 2014 13:53 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
How do I get hour value from sysdate in 24 hour format (the result should be only number, not varchar value) ?


Exmaple?
What should be the result for:
SQL> select sysdate from dual;
SYSDATE
-------------------
16/08/2014 20:53:24


Re: get hour value from sysdate in 24 hour format [message #621723 is a reply to message #621720] Sat, 16 August 2014 14:01 Go to previous messageGo to next message
ecivgamer
Messages: 147
Registered: May 2011
Location: Ukraine
Senior Member
BlackSwan wrote on Sat, 16 August 2014 21:27
use TO_CHAR() & TO_NUMBER()


thanks,

the solution:
select to_number(to_char(sysdate,'HH24')) from dual;
Re: get hour value from sysdate in 24 hour format [message #621724 is a reply to message #621723] Sat, 16 August 2014 14:30 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member

SQL> SELECT TO_CHAR(SYSDATE,'HH24') HOUR1, TO_NUMBER(TO_CHAR(SYSDATE,'HH24')) HOUR2 FROM DUAL;

HO      HOUR2
-- ----------
11         11


Previous Topic: get number of week day - no matter what national locale is used
Next Topic: table should allow to insert only one row
Goto Forum:
  


Current Time: Thu Apr 25 17:34:46 CDT 2024