Convert string to time of day [message #402325] |
Fri, 08 May 2009 14:56  |
deahayes3
Messages: 203 Registered: May 2006
|
Senior Member |

|
|
Hello everyone,
I am having a problem with the correct time showing in a table. When the time is entered on the form, for example 11:24 when it saves to the table it saves as 41040. How can I convert this back to 11:24 without changing the data type in the table which by the way is of Varchar. Another example is 08:00 converts to 28800. Is this seconds? I dont understand this conversion, is there a math equation I can use to convert it back to real time.
|
|
|
|
|
|
|
|
|
|
Re: Convert string to time of day [message #402350 is a reply to message #402336] |
Sat, 09 May 2009 01:27   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
And for those of you who want to use Oracle's date functions like they were meant to be used:
SQL> select to_char(trunc(sysdate) + &n/(24*60*60), 'HH24:MI:SS') from dual;
Enter value for n: 28800
old 1: select to_char(trunc(sysdate) + &n/(24*60*60), 'HH24:MI:SS') from dual
new 1: select to_char(trunc(sysdate) + 28800/(24*60*60), 'HH24:MI:SS') from dual
TO_CHAR(
--------
08:00:00
SQL> select to_char(trunc(sysdate) + &n/(24*60*60), 'HH24:MI:SS') from dual;
Enter value for n: 41040
old 1: select to_char(trunc(sysdate) + &n/(24*60*60), 'HH24:MI:SS') from dual
new 1: select to_char(trunc(sysdate) + 41040/(24*60*60), 'HH24:MI:SS') from dual
TO_CHAR(
--------
11:24:00
Don't try to re-invent the wheel
|
|
|
|
|
Re: Convert string to time of day [message #402357 is a reply to message #402336] |
Sat, 09 May 2009 04:11  |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
deahayes3 wrote on Fri, 08 May 2009 22:07 | For those of you that would like to know the pl/sql version
SELECT TO_CHAR(TRUNC(:n/60/60),'09') ||
TO_CHAR(TRUNC(MOD(:n,3600)/60),'09') ||
TO_CHAR(MOD(MOD(:n,3600),60),'09')
FROM dual;
|
No PL/SQL there. Just SQL. (Or is it that it's Friday and their definitions change?)
|
|
|