4D v16.3

Date

Home

 
4D v16.3
Date

Date 


 

Date ( dateString ) -> Function result 
Parameter Type   Description
dateString  String in String representing the date to be returned
Function result  Date in Date

The Date command evaluates dateString and returns a date.

The dateString parameter format must follow either the ISO date format or the regional settings defined at the system level.

ISO date format
The string must be formatted as follows: "YYYY-MM-DDTHH:MM:SS", for example "2013-11-20T10:20:00". In this case, Date evaluates the dateString parameter correctly, whatever the current language settings. Decimal seconds, preceded by a period, are supported (e.g.: "2013-11-20T10:20:00.9854").
If the dateString format does not precisely fit this ISO schema, then the date is evaluated as a short date format based on the regional settings of the system.

Note : Starting with 4D v14, it is recommended to use the "YYYY-MM-DDTHH:MM:SSZ" format, compliant with the ISO standard and allowing to express the time zone.

Regional settings
When the dateString does not match the ISO format, the regional settings defined in the operating system for a short date are used for the evaluation. For example, in the US version of 4D, by default the date must be in the order MM/DD/YY (month, day, year). The month and day can be one or two digits. The year can be two or four digits. If the year is two digits, then Date considers whether the date belongs to the 21st or 20th century based on the value entered. By default, the pivotal value is 30:

  • If the value is greater than or equal to 30, 4D considers the century to be the 20th and adds 19 to the beginning of the value.
  • If the value is less than 30, 4D considers the century to be the 21st and adds 20 to the beginning of the value.

This mechanism can be configured using the SET DEFAULT CENTURY command.
The following characters are valid date separators: slash (/), space, period (.), comma (,), and dash (-).

If you pass an invalid date (such as "13/35/94" or "aa/12/94") in dateString, Date returns a null date (!00/00/00!). It is your responsibility to verify that dateString is a valid date.

The following example uses a request box to prompt the user for a date. The string entered by the user is converted to a date and stored in the reqDate variable:

 vdRequestedDate:=Date(Request("Please enter the date:";String(Current date)))
 If(OK=1)
  ` Do something with the date now stored in vdRequestedDate
 End if

The following example returns the string "12/25/94" as a date:

 vdDate:=Date("12/25/94")

Date evaluation based on a date in ISO format:

 $vtDateISO:="2013-06-05T20:00:00"
 $vDate:=Date($vtDateISO)
  //$vDate represents June 5th, 2013 regardless of the system language

 
PROPERTIES 

Product: 4D
Theme: Date and Time
Number: 102

This command can be run in preemptive processes

 
HISTORY 

Created: < 4D v6

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)