convert_date()
Convert the Gregorian date and time to the number of seconds that have elapsed since 00:00:00 GMT January 1, 1970.
Syntax
convert_date(day month date time [timezone] year,[timezone])
convert_date(day month date time year,[timezone])
Parameters
Parameter | Definition |
---|---|
day | three-character string representing the day of the week*Valid Values* |
date | integer day of the month*Valid Values* |
month | three-character string representing the month Valid Values |
year | integer year*Valid Values* |
time | eight-character string in the form hh : mm : ss representing the time*Valid Values* |
timezone | optional time zone for which the conversion is being performed*Valid Values*
|
timezone |
|
timezone | Relative Time Zones |
Description
The convert_date() function returns an integer that is the number of seconds past 00:00:00 GMT January 1, 1970 of the specified date and time string. The convert_date() command can parse any of three date and time string formats:
- RFC-822 format (day, date month year time timezone)
- Unix format (day month date time timezone year)
- PSL date() function format (day month date time year)
The convert_date() function requires the timezone parameter to correctly convert the date and time. If timezone is not specified, either in the date and time string (RFC-822 and Unix formats) or as a separate parameter (all formats), the convert_date() function uses the time zone defined for the machine on which it is executing.
If the convert_date() function encounters an error, it returns a zero and sets the PSL errno variable as follows:
errno Value | Description |
---|---|
111 | E_PSL_BAD_DATE_STRING-- indicates that the convert_date() function could not parse the date and time string |
112 | E_PSL_BAD_TIMEZONE -- indicates that the convert_date() function did not recognize the specified timezone |
113 | E_PSL_CANNOT_DETERMINE_TIMEZONE -- indicates that the convert_date() function is using timezone = GMT because notimezone was supplied and the time zone used by the system could not be determined |
Example
The following convert_date() function calls illustrate the different ways to specify the timezone parameter:
seconds = convert_date("Fri Mar 8 11:39:07 CST 1996");
print("Converted time is ",seconds,"\n");
# Specify timezone as a separate parameter
seconds = convert_date("Fri Mar 8 11:39:07 1996","CST");
print("Converted time is ",seconds,"\n");
# Use time zone defined in the operating system
seconds = convert_date("Fri Mar 8 11:39:07 1996");
print("Converted time is ",seconds,"\n");
In the case where the operating system uses the CST time zone, the example produces the following output:
Converted time is 826306747
Converted time is 826306747