| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

08-18-04, 08:59
|
|
Registered User
|
|
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
|
|
|
Problems with DAYS() function
|
|
I have a funny situation with using the DAYS() function:
1.Select DAYS(CURRENT DATE) - DAYS(FIRSTDAY) from TABLE
gives incorrect output (far too high)
2.Select RESUMEDDAY - FIRSTDAY from TABLE
(both datefields) gives proper results.
3.Select CURRENT DATE - FIRSTDAY from TABLE
returns ridiculous high integers, even much higher than 1.
4. Select TIMESTAMPDIFF(16,CHAR(CURRENT DATE - FIRSTDAY)) from TABLE
returns about the same output as 1. , but slightly lower
What am i missing to work with the system date ?
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
|
|

08-18-04, 09:39
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
I think your problem is how date, time, and timestamp arithmatic is done.
Using your examples:
1) will return the number of days between the two dates as an integer
2) and 3) return a duration (decimal) that is a representation of years, months and days between dates (YYYYMMDD.)
4) TIMESTAMPDIFF returns an approximation
Examples I just ran:
DB:LCAD->select days(current date) - days('08/01/2004') from sysibm.sysdummy1
1
-----------
17
1 record(s) selected.
DB:LCAD->select current date - '08/01/2004' from sysibm.sysdummy1
1
----------
17.
1 record(s) selected.
DB:LCAD->select days(current date) - days('08/01/1994') from sysibm.sysdummy1
1
-----------
3670
1 record(s) selected.
DB:LCAD->select current date - '08/01/1994' from sysibm.sysdummy1
1
----------
100017.
1 record(s) selected.
DB:LCAD->select timestampdiff(16,char(current date -'08/01/2004')) from sysibm.sysdummy1
1
-----------
17
1 record(s) selected.
Read the SQL Reference manual on date, time, and timestamp arithmatic.
HTH
Andy
|
|

08-19-04, 05:37
|
|
Registered User
|
|
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
|
|
|
|
Sorry to bring up the subject. I was missing the fact that a lot of the data was from year 2003 
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
|
|

08-19-04, 08:03
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Maybe if you would post the results you are getting. I may be able to help you more.
Andy
|
|

08-19-04, 08:22
|
|
Registered User
|
|
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
|
|
No. I mean the issue is resolved with the high figures. I was expecting to compare 2004 dates with current date, but a lot of the data was from 2003. And hence the high values..... 
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|