www.icetips.com  Icetips Utilities Documentation 11/14/2010    

Date Class: DateDiff

Previous  Top  Next  


Prototype: (Byte pDatePart=1, Date pStartDate, Date pEndDate),Long

 

pDatePartIndicates what type of unit to use.  Can be IT_Days, IT_Weeks, IT_Months or IT_Years.  Defaults to IT_Days
pStartDateThe start date to compare to the pEndDate parameter.
pEndDateThe end date to compare to the pStartDate parameter.

 

ReturnsThe number of boundaries crossed between the two specified dates.

 

This method is compatible with the DATEDIFF function in MSSQL and several other SQL dialects.  It takes two dates and counts the boundaries for the specified unit between the two dates.  For example if you use Monday last week to Tuesday this week and use IT_Weeks as unit, it will return 1 week.  If you use July 31st as pStartDate and August 1st as pEndDate and IT_Month as unit the function will return 1 as the boundaries between months have been crossed once.  Same if you use July 1st and August 31, it will still return only 1 as only one month boundary has been crossed.  Note that MSSQL uses Sunday as week start day so to get a 100% MSSQL compatible DateDiff you need to use SetWeekStartDay(IT_Sunday) before you use DateDiff or DateAdd.

 

Example:

ITD  ITDateClass

FD   Date

TD   Date

D    Date

Ds   Long

Code

FD = Date(7,1,2010)

TD = Date(8,24,2011)

ITD.SetWeekStartDay(IT_Sunday)

 

ITD.ODS('DateDiff Days   FD: ' & Format(FD,@d18) & ', TD: ' &|

         Format(TD,@d18) & ' = ' & ITD.DateDiff(IT_Days,FD,TD))   !! 409 days

ITD.ODS('DateDiff Weeks  FD: ' & Format(FD,@d18) & ', TD: ' &|

         Format(TD,@d18) & ' = ' & ITD.DateDiff(IT_Weeks,FD,TD))  !! 60 weeks

ITD.ODS('DateDiff Months FD: ' & Format(FD,@d18) & ', TD: ' &|

         Format(TD,@d18) & ' = ' & ITD.DateDiff(IT_Months,FD,TD)) !! 13 months

 

See also:

SetWeekStartDay

DateAdd

GetDate

 



Direct link to this page: http://www.icetips.com/manuals/utilities/datediff_dateclass.htm