Count days between 2 dates
0 pts.
0
Q:
Count days between 2 dates
I wish to, using query count the number of days between 2 dates, the dates are in YYYMMDD format but I presume I'll need to convert the dates to Julian first to allow the caculation.
Can anyone help?
ASKED: Feb 27 2007  8:25 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
0 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
whenever possible I do these calculations in SQL server. Using SQL server, the syntax is simple. DB2 is a bit more complex. Here are examples in both.

SQL Server:
select convert(datetime, convert(varchar, fieldname + 19000000)) from ...

DB2:
SELECT date(substr(digits(fieldname + 19000000),2,4)||'-'||substr(digits(fieldname + 19000000),6,2)||'-'|| substr(digits(fieldname + 19000000),8,2)) FROM library/file

I'm assuming you're YYYMMDD is 990227 for 1999 and 1070227 for 2007, and that the dates are stored in a numeric field. if they're in a string field things are a bit more complex, but not impossible. Once you have the fields in a datetime format, you can use normal date comparison/arithmetic on them.

Hope that helps,
Kevin
Last Answered: Feb 27 2007  8:54 AM GMT by MODMOD   0 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

WaltZ400   535 pts.  |   Feb 27 2007  12:20PM GMT

If you are using SQL and your dates are stored in true date format in your data base, you can use the DAYS function. This translate a date into a numeric value that you subtract from another. An example is:

Select Days(enddate) - Days(fromdate)from file Where Days(enddate) - Days(fromdate) > 10

 
0