View previous topic :: View next topic
|
Author |
Message |
zacharti
New User
Joined: 15 Jun 2006 Posts: 13
|
|
|
|
Hi,
I have a requirement to convert time into its corresponding minutes usig DB2 SQL query in mainframe.
Is there any funtion available that directly converts the time into its corresponding minutes?
For eg: if the time is 13:38, it should be converted into 7838 minutes
(13* 60 +38)
Thanks
Tita |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Either you're using a mathematical system I'm not familiar with, or you want something I'm not sure you can get from the system.
13 times 60 is 780
Add 38 for a result of 818
Since there are only 1,440 minutes in a day, if you're wanting minutes elapsed since midnight, the value should range from 0 to 1439. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
I would suggest using the function MIDNIGHT_SECONDS and divide the result by 60 to get the minutes count. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
no function directly converts hours or days to minutes.
depending upon your time column,
the following scalar functions can combined:
MINUTE can be used to extract the minute portion of a time, date, timestamp datatype
HOUR can be used to extract the hour portion of a time, date, timestamp datatype and when multipled by 60 gives the number of minutes for the hour(s).
so,
SELECT (HOUR(datetime_column type) * 60) + (MINUTE(datetime_column type)) as Number_Of_Mminutes.
you can cast a host variable as a datetime datatype.
but if you are using db2 to calculate minutes of a host variable containing HH:MM you are wasting resources.
or use Kjeld's suggestion, but MIDNIGHT_SECONDS also expects a datetime datatype. |
|
Back to top |
|
|
|