Break on
;use positive to look into the future.
;use negative to look at the past.
$mod = -30
? ? "in/before $mod day(s) it was/will be " + DateCalc(@date, $mod)
Sleep 5
;FUNCTION DateCalc()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
; based on date algorithms by Peter Baum to be found here :
; http://www.capecod.net/~pbaum/date/date0.htm
;
;VERSION 1.12
;
;VERSION HISTORY 1.0 2001/12/10 Initial release
;
; 1.1 2004/02/18 Added support for single digit month/day input
; and optional single digit month/day date return
;
; 1.11 2004/02/20 Minor Variable handling fix
;
; 1.12 2005/03/31 Finally supports "NoVarsInStrings" and "Explicit" set to "ON" in
; all possible variations
;
;ACTION Calculates days between 2 dates or returns a date string calculated from
; a given date and a given amount of days ( Addition of positive or negative
; integer value )
;
;SYNTAX DateCalc( Date1, Date2|Modifier, [SingleDigit] )
;
;PARAMETERS Date1 (Required)
; - (Gregorian) Date string in Format : YYYY/M[M]/D[D]
;
; Date2|Modifier (Required)
; - either a second (Gregorian) date string (YYYY/M[M]/D[D]) to calculate days between
; or a positive/negative amount of days to calculate with
;
; SingleDigit (Optional)
; - if not zero date will be returned unpadded, eg. 2004/2/9
;
;REMARKS Date format must be KiX friendly : YYYY/M[M]/D[D] (2001/11/20)
; To calculate a date less than given assign a negative integer (ie. -45 )
;
;RETURNS Either a positive integer value of days between two given dates,
; or a (Gregorian) date string.
;
;DEPENDENCIES None !
;
;EXAMPLES
; break on
; call "[path]DateCalc.udf"
;
; "boot.ini last modified : " + DateCalc(@date,substr(getfiletime("c:\boot.ini"),1,10))
; + " days ago ..." ? ?
;
; $mod = 60
; "in/before $mod day(s) it was/will be " + DateCalc(@date,$mod) ? ?
;
; get $
Function DateCalc($date1, $DateOrMod, optional $SingleDigit)
Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1
Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2
$date1 = Split($date1, '/')
If UBound($date1) <> 2
Exit 1
EndIf
$_intYear1 = Val($date1[0])
$_intMonth1 = Val($date1[1])
$_intDay1 = Val($date1[2])
If $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
EndIf
$_intDate1 = $_intDay1 + (153 * $_intMonth1 - 457) /5 + 365 * $_intYear1 +
$_intYear1 /4 - $_intYear1 /100 + $_intYear1 /400 - 306
Select
Case VarType($DateOrMod) = 3
$_intDate2 = $_intDate1 + $DateOrMod
If InStr($_intDate2, '-') $_intDate2 = Val(SubStr($_intDate2, 2, Len($_intDate2) - 1)) EndIf
$_intYear2 = ( 100 * ( ((100 * ($_intDate2 + 306) - 25) /3652425)
- (((100 * ($_intDate2 + 306) - 25) /3652425) /4)
) + (100 * ($_intDate2 + 306) - 25)
) /36525
$_intMonth2 = ( 5 * ( ((100 * ($_intDate2 + 306) - 25) /3652425)
- (((100 * ($_intDate2 + 306) - 25) /3652425) /4)
+ ($_intDate2 + 306) - 365 * $_intYear2 - $_intYear2 /4
) + 456
) /153
$_intDay2 = ( ((100 * ($_intDate2 + 306) - 25) /3652425)
- (((100 * ($_intDate2 + 306) - 25) /3652425) /4)
+ ($_intDate2 + 306) - 365 * $_intYear2 - $_intYear2 /4
) - ( 153 * $_intMonth2 - 457
) /5
If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf
If Not $SingleDigit
If Len($_intYear2) < 4
$_ = Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next")
EndIf
$_intMonth2 = Right("0" + $_intMonth2, 2)
$_intDay2 = Right("0" + $_intDay2, 2)
EndIf
$DateCalc = '' + $_intYear2 + '/' + $_intMonth2 + '/' + $_intDay2
Case VarType($DateOrMod) = 8
$DateOrMod = Split($DateOrMod, '/')
If UBound($DateOrMod) <> 2
Exit 1
EndIf
$_intYear2 = Val($DateOrMod[0])
$_intMonth2 = Val($DateOrMod[1])
$_intDay2 = Val($DateOrMod[2])
If $_intMonth2 < 3
$_intMonth2 = $_intMonth2 + 12
$_intYear2 = $_intYear2 - 1
EndIf
$_intDate2 = $_intDay2 + (153 * $_intMonth2 - 457) /5 + 365 * $_intYear2 +
$_intYear2 /4 - $_intYear2 /100 + $_intYear2 /400 - 306
$DateCalc = $_intDate1 - $_intDate2
;comment the next line if you wish to return negative results also !!!
If InStr($DateCalc, '-') $DateCalc = Val(SubStr($DateCalc, 2, Len($DateCalc) - 1)) EndIf
Case 1
Exit 1
EndSelect
EndFunction