This function will calculate the interval between two dates -OR- add an interval to a specified date. Supports the following intervals; seconds, minutes, hours, days, and weeks.

I'm asking for comments or suggestions for improvement.

Thanks!

"One second after midnight: " + fnDateDiff(@DATE,1,"s") ??
"Seconds between today and tomorrow: " + fnDateDiff(@DATE,fnDateDiff(@DATE,1,"d"),"s",0) ??
"Weeks between today and six days from today: " + fnDateDiff(@DATE,fnDateDiff(@DATE,6,"d"),"w",0) ??
"Weeks (fixed) between today and six days from today: " + fnDateDiff(@DATE,fnDateDiff(@DATE,6,"d"),"w",1) ??
"Shopping days until my birthday: " + fnDateDiff(@DATE,"2006/04/20","d") ??
"Seconds between 1/1/1601 and 1/1/1970: " + fnDateDiff("01/01/1601","01/01/1970") ??
"Hours between NOW and 9/18/2005 13:00: " + fnDateDiff(@DATE+' '+@TIME,"09/18/2005 13:00:00","h") ??
"Seconds between midnight and 11:59:59 pm: " + fnDateDiff("00:00:00","23:59:59","s",0) ??
"Add one minute to midnight: " + fnDateDiff("00:00:00",1,"m",0) ??
"VarTypeName of fnDateDiff output: " + VarTypeName(fnDateDiff(@TIME,0,"s")) ??
"VarTypeName of @@TIME: " + VarTypeName(@TIME) ??
@SERROR ?

Get $

Function fnDateDiff($sDate,$DateOrInterval,Optional $Interval,$Fix)
Dim $objDateTime
$objDateTime = CreateObject("WbemScripting.SWbemDateTime")
If @ERROR Exit 10 EndIf
$objDateTime.SetVarDate($sDate)
If @ERROR Exit 1901 EndIf
$sDate=$objDateTime.GetFileTime

If InStr($DateOrInterval,"/") or InStr($DateOrInterval,":")
$objDateTime.SetVarDate($DateOrInterval)
If @ERROR Exit 1901 EndIf
$DateOrInterval=$objDateTime.GetFileTime
$fnDateDiff=(CDbl($DateOrInterval)-CDbl($sDate))/10000000
Select
Case $Interval="s"
Case $Interval="m" $fnDateDiff=$fnDateDiff/60
Case $Interval="h" $fnDateDiff=$fnDateDiff/3600
Case $Interval="d" $fnDateDiff=$fnDateDiff/86400
Case $Interval="w" $fnDateDiff=$fnDateDiff/604800
Case 1 Exit 87
EndSelect
If $Fix $fnDateDiff=Fix($fnDateDiff) EndIf
Else
If VarType($DateOrInterval)>5 Exit 87 EndIf
Select
Case $Interval="s" If VarType($DateOrInterval)>3 Exit 87 EndIf
Case $Interval="m" $DateOrInterval=$DateOrInterval*60
Case $Interval="h" $DateOrInterval=$DateOrInterval*3600
Case $Interval="d" $DateOrInterval=$DateOrInterval*86400
Case $Interval="w" $DateOrInterval=$DateOrInterval*604800
Case 1 Exit 87
EndSelect
$objDateTime.SetFileTime(''+(CDbl($sDate)/10000000+CDbl($DateOrInterval))+"0000000")
If @ERROR Exit @ERROR EndIf
$fnDateDiff=$objDateTime.GetVarDate
EndIf
EndFunction