|
|
|
| 25 March 2002 | DateMath() |
| Author | ScriptLogic Corporation |
| Action | Performs mathematical computations on a date or computers days between two dates. |
| Syntax | DateMath ("date1", "date2") -or- DateMath ("date1", integer) |
| Parameters | |
| Remarks | Date parameters must be in the form of YYYY/MM/DD. |
| Returns | If two dates are passed, the number of days between them is returned as in integer. If a date is passed as "date1" and a number of days is passed as integer, the resulting date will be returned in the form of YYYY/MM/DD. |
| Dependencies | SerialDate() |
| Examples |
$DaysBetween=Datemath("2001/04/01","1999/01/01")
$LastWeek=DateMath(@Date,-7)
|
| Source |
FUNCTION DateMath ($expd1, $expd2)
; Author: ScriptLogic Corporation
; if both parameters are dates (yyyy/mm/dd), a positive integer indicating
; the days between the two dates will be returned.
; if the first is a date (yyyy/mm/dd) and the second is an integer
; (number of days), a new date will be returned.
;
; UDF dependencies: SerialDate, Abs
SELECT
CASE InStr($expd1,'/') AND InStr($expd2,'/')
; two date passed - return daysbetween integer
$datemath=serialdate($expd1)-serialdate($expd2)
IF ($datemath < 0)
$datemath=$datemath*-1
ENDIF
CASE InStr($expd1,'/') AND 1-InStr($expd2,'/')
; date and a number passed - return date
$expd2=0+$expd2
$datemath=serialdate(serialdate($expd1)+$expd2)
CASE 1
; incorrect parameters passed
ENDSELECT
ENDFUNCTION ; - DateMath -
|
|
|
|