Stores and manipulates date and time.
The DATE type is implemented using a floating-point number (double). Days are represented by whole number increments starting with 30 December 1899, midnight as time zero. Time values are expressed as fractional part. Time precision is 1 second. Also can be used to represent date-only (the fractional part is 0) or time-only (the whole number part is 0).
To remove the time part (leave only the date part) from a DATE variable, you can assign it to an int variable. However, when converting DATE to int, result may be rounded up. To prevent it, use the member variable date. See the example.
DATE supports operator = (assign). Use it to convert string (str, lpstr, BSTR, VARIANT), containing date, to DATE, and vice versa.
To format date/time string, use str.timeformat.
You can instead use DateTime class. Its purpose is the same as of DATE. It has more functions and supports milliseconds.
To store date and time, also often are used types SYSTEMTIME and FILETIME:
type SYSTEMTIME @wYear @wMonth @wDayOfWeek @wDay @wHour @wMinute @wSecond @wMilliseconds type FILETIME dwLowDateTime dwHighDateTime
Here var is a variable of type DATE. Where the return type is not specified, the function returns var itself.
var.add(diff)
Adds diff to var. Here diff is a date span variable. With DATE functions, date span (difference between two dates) is a variable of type SYSTEMTIME.
Use this function when date span is quite complex. To add/subtract days, you can use operator + or -. For example, var=var-2 subtracts 2 days; var=var+(4/24.0) adds 4 hours.
var.sub(diff)
Subtracts diff from var.
double var.diff(date2 [diff] [part])
Returns difference between var and date2. The return value is negative if var is less than date2, 0 if var is equal to date2, positive if var is greater than date2.
diff can be 0 or a variable of type SYSTEMTIME. It receives date span (always positive).
By default, returns difference in days. If part is 1 then returns difference in hours, 2 - minutes, 3 - seconds.
Always returns whole number. To get exact difference between two dates, use operator -. Example: diff=var-date2.
var.fromsystemtime(st)
Converts types: SYSTEMTIME to DATE. Here st is a variable of type SYSTEMTIME.
var.tosystemtime(st)
Converts types: DATE to SYSTEMTIME. Here st is a variable of type SYSTEMTIME.
var.fromfiletime(ft)
Converts types: FILETIME to DATE. Here ft is a variable of type FILETIME.
var.tofiletime(ft)
Converts types: DATE to FILETIME. Here ft is a variable of type FILETIME.
var.getclock
Gets current time.
DATE d="4/1/2003" add 2 days d=d+2 out d subtract 1 hour SYSTEMTIME st st.wHour=1 out d.sub(st) get difference in hours out d.diff("4.1.2003" st 1) out "%i/%i/%i %i:%i:%i" st.wMonth st.wDay st.wYear st.wHour st.wMinute st.wSecond remove the time part DATE d=10.55 int i=d out i ;;11 (rounded up) i=d.date out i ;;10 (ok)