Table of Contents

6.01 Date

Returns the current date in one of several different formats. Optionally it will convert a supplied date from one supported format to another. It will also adjust the current or supplied date by a specified number of days.

Date

Description:

Date returns the current date or a supplied date in one of several different formats. Optionally it can adjust the date by a specified number of days.

Syntax:

date([option_out [,option_in [,date [,adjust]]]])

Parameters:

option_out
One of International, European, American(USA), Sorted(Standard), Base, Days, Timestamp or Weekday.
Note that only the first character is used. Any remaining characters are ignored. This will apply even if the word is spelled incorrectly.
option_in
One of International, European, American(USA), Sorted(Standard), Base, Day, Timestamp or Weekday.
If this option is specified, it defines the format of the date in the following parameter.
date
Date to be used as source in the format specified by option_in. If this date is omitted, option_in is ignored and the current date is used.
adjust
An adjustment to be applied to the input date. This is a whole number of days to be added or subtracted. A positive value gives a date in the future.

Return Value:

A string containing the current, converted and/or adjusted date depending on the options specified.

Remarks:

Where an output option only is specified the current date is converted to the that format.

If there is no option or the option is invalid, the current date is returned in the International format: yyyy-mm-dd.

If an input date is specified, that date is used instead of the current date.

If an adjustment is specified this number of days is added or subtracted to the input date. A positive value gives a date in the future.

International
International/ISO date in the format: yyyy-mm-dd (yyyy, mm, and dd all have leading zeros).
European
European date in the format: dd/mm/yyyy (dd, mm, and yyyy all have leading zeros).
American(USA)
USA date in the format: mm/dd/yyyy (mm, dd, and yyyy all have leading zeros).
Sorted(Standard)
Sortable date in the format: yyyymmdd (suitable for sorting - yyyy, mm, and dd all have leading zeros).
Base
The number of complete days (that is, not including the current day) since and including the base date, 1 January 0001, in the format: dddddd (no leading zeros or blanks). The expression date('B') mod 7 returns a number in the range 0–6 that corresponds to the current day of the week, where 0 is Monday and 6 is Sunday. This function can therefore be used to determine the day of the week independent of the national language in which you are working. 1)
Days
The number of days, including the current day, so far in the current year in the format: ddd (no leading zeros or blanks).
Timestamp
Unix timestamp as a decimal number. This is the number of seconds since 01/01/1970 00:00:00 UTC until 00:00:00 today.
Weekday
The number of the day of the week starting with Monday. Monday is 1 and Sunday is 7.

The first call to date or time in one clause causes a time stamp to be made that is then used for any further calls to date or time in that clause. This means that multiple calls to either function in a single expression or clause will be consistent with each other.

Examples:
Here are some examples for the date 31 August 2008:

date()    -> '2008-08-31'
date('I') -> '2008-08-31'
date('E') -> '31/08/2008'
date('A') -> '08/31/2008'
date('S') -> '20080831'
date('T') -> '1220140800' /* Seconds since 01/01/1970 00:00:00 UTC */
date('B') -> '733284'     /* Whole days since 01/01/0001 00:00:00 */
date('D') -> '244'
date('W') -> '7'          /* Sunday */

Convert dates from ISO with adjustment:

date('B','I','2008-08-31',-3) -> '733281'
date('D','I','2008-08-31',-2) -> '242'
date('E','I','2008-08-31',-1) -> '30/08/2008'
date('A','I','2008-08-31',+1) -> '09/01/2008'
date('S','I','2008-08-31',+2) -> '20080902'  
date('T','I','2008-08-31',+3) -> '1220400000'

Implementation Status:

LynPlex Interpreter
Fully implemented
The 's' option is to be dropped and used instead for the date serial format.
LynPlexC Compiler
Currently the date function returns the ISO format date only, otherwise there is limited support revolving around VB date serials.
LynPlexS Compiler
To be implemented
Currently there is limited support for date handling using the following Xst library functions.
XstDateAndTimeToFileTime
XstFileTimeToDateAndTime
XstGetDateAndTime
XstGetDateAndTimeFormatted
XstGetSystemTime
XstSetDateAndTime

See Also:

1) The base date of 1 January 0001 is determined by extending the current Gregorian calendar backward by 365 days each year, with an extra day for every year that is divisible by 4 with the exception of century years that are not divisible by 400. It does not take into account any errors in the calendar system that created the Gregorian calendar originally.

lynplex/lp0601.txt · Last modified: 2014/12/29 14:02 by don