ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Date and time functions
  • Validity of date time
  • Date time format
  • Special case: is not specified
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Converts a DateTime to string in the specified format.
Tip: The return value of this function must not be assigned to a "Date" Edit control (with an input mask including the date and time) that expects a string without separators (e.g.: "202004281500").
Example
Res = DateTimeToString("201912251715") // Res = "25/12/2019 17:15:00:00"
 
Res = DateTimeToString(RealToDateTime(73773,5)) // Res = "25/12/2001 00:00:00:00"
 
DateTimeToString("") // Returns ""
 
Res = DateTimeToString("201912251715", "MM-DD-YYYY H:mm AP") // Res = "12-25-2019 5:15 PM"
 
Res = DateTimeToString("201912251715", ...
"Day # DD of the month # MM, YYYY at HH and mm minutes")
 
Res = DateTimeToString(SysDateTime(), maskDateSystem)
// Res uses the format defined in the project
 
// The case used for the days and months depends on the project language options
Res = DateTimeToString("202012021715", "DDD MMM D YYYY H:mm AP")
// Res = "Wed. Dec. 2 2020 5:15 PM"
 
Res = DateTimeToString("202012021715", "DDDD MMMM D YYYY H:mm AP")
// Res = "Wednesday, December 2 2020 5:15 PM"
 
// You can force the use of uppercase letters for days and months
Res = DateTimeToString("202012021715", "Ddd Mmm D YYYY H:mm AP")
// Res = "Wed. Dec. 2 2020 5:15 PM"
Res = DateTimeToString("202012021715", "Dddd Mmmm D YYYY H:mm AP")
// Res = "Wednesday, December 2 2020 5:15 PM"
 
Res = DateTimeToString("201911251715", maskDateEmail)
// Returns "Mon, 25 Nov 2019 17:15:00 +0100"
 
Res = DateTimeToString("201908251715", maskDateEmail)  
// Returns "Sun, 25 Aug 2019 17:15:00 +0200"
 
Res = DateTimeToString("201911250015", maskDateEmailUTC)
// Returns "Sun, 24 Nov 2019 23:15:00 +0000"
 
Res = DateTimeToString("201908251715", maskDateInternet)  
// Returns "2019-08-25T17:15:00.000+02:00"
 
Res = DateTimeToString("201908250015", maskDateInternetUTC)  
// Returns "2019-08-24T22:15:00.000Z"
 
// On 09/02/2020 at 11:00 AM
Res = DateTimeToString("202001011715", maskDateRelativeDuration)
// Returns: 8 months ago
 
Res = DateTimeToString("202011251715", maskDateRelativeDuration)
// Returns: next year
 
Res = DateTimeToString("202001181715", maskDateRelativeDuration)
// Returns: in 6 hours
Syntax
<Result> = DateTimeToString(<Data to convert> [, <Format>])
<Result>: Character string
Character string in the specified format.
<Data to convert>: Character string or DateTime variable
Local date and time to convert. Can correspond to:
  • a DateTime variable.
  • a character string with one of the following formats:
    • YYYYMMDDHHmmSSCCC
    • YYYYMMDDHHmmSSCC
    • YYYYMMDDHHmmSS
    • YYYYMMDDHHmm
    • YYYYMMDDHH
    • YYYYMMDD
This parameter will be considered invalid in the following cases:
  • if the date is invalid or earlier than 01/01/1970. You can check the validity of a date using DateValid.
  • if the time is invalid. You can check the validity of a time using TimeValid.
Remark: It is possible to use dates beyond 2038.
<Format>: Optional character string
Format of the converted date and time. This parameter can contain a word, a sentence, ... The characters that represent the different elements of the date and time will be automatically replaced with the value in the <Date to convert> parameter. In this string:
  • YYYY represents a 4-digit year,
  • YY represents a 2-digit year,
  • M represents the month without a leading zero,
  • MM represents a 2-digit month,
  • MMM represents a 3-letter month (e.g., Jan). The case used depends on the language options of the project.
  • Mmm represents a 3-letter month with the first letter in uppercase (e.g., Jan)
  • mmm represents a 3-letter month with the first letter in lowercase (e.g., jan)
  • MMMM represents the month as a full name (e.g., January). The case used depends on the language options of the project.
  • Mmmm represents the month as a full name with the first letter in uppercase (e.g., January)
  • mmmm represents the month as a full name with the first letter in lowercase (e.g., january)
  • D represents the day without a leading zero,
    DD represents a 2-digit day,
  • DDD represents a 3-letter day (e.g., Mon). The case used depends on the language options of the project.
  • Ddd represents a 3-letter day with the first letter in uppercase (e.g., Mon)
  • ddd represents a 3-letter day with the first letter in lowercase (e.g., mon)
  • DDDD represents the day as a full name (e.g., Monday). The case used depends on the language options of the project.
  • Dddd represents the day as a full name with the first letter in uppercase (e.g., Monday)
    dddd represents the day as a full name with the first letter in lowercase (e.g., monday)
  • M represents the first letter of the day (e.g., M,T,W,T,F,S,S)
  • HH represents the number of hours,
  • mm represents the number of minutes,
  • SS represents the number of seconds,
  • CC represents the number of hundredths of a second,
  • CCC represents the number of thousandths of a second,
  • AP represents "AM" or "PM" (if "AP" is used, the time is displayed in 12-hour format).
If this parameter corresponds to the constant:
maskDateEmailThe format used corresponds to the date time format of the RFC-5322 standard used to encrypt emails, RSS feeds, etc, ...
The result is expressed in the local time zone.
WEBDEV - Browser codeAndroidJavaPHP Not available.
maskDateEmailUTCThe format used corresponds to the date time format of the RFC-5322 standard used to encrypt emails, RSS feeds, etc, ...
The result is expressed in universal time (UTC).
WEBDEV - Browser codeAndroidJavaPHP Not available.
maskDateInternetThe format used corresponds to the date time format of the RFC-3339 standard used for international communications.
The result is expressed in the local time zone.
maskDateInternetUTCThe format used corresponds to the date time format of the RFC-3339 standard used for international communications.
The result is expressed in universal time (UTC).
WEBDEV - Browser code Not available.
maskDateRelativeDurationThis format is used to express the time elapsed (or that will elapse) between the current date time and the specified date time. This format is expressed in natural language. The different formulations used can be configured in the project description for the current language:
  1. On the "Project" tab, in the "Project" group, click "Description".
  2. In the "Languages" tab:
    • select the language to configure.
    • select the "Date" tab.
  3. Click the "Dates and Times in natural language" button.
  4. Define (if necessary) the custom captions to use. These captions will be used:
    • for the result of DateTimeToString.
    • for the controls that use the "Relative duration" display mask.
WEBDEV - Browser code Not available.
maskDateSystemThe format used corresponds to the format defined in the project description for the current language:
  1. On the "Project" tab, in the "Project" group, click "Description".
  2. Select the "Languages" tab then the "Date" tab.
  3. The date format used corresponds to:
    • the settings of the operating system,
    • the specified parameters (with the defined days and months).
  4. Select the "Languages" tab then the "Time" tab.
  5. The time format used corresponds to:
    • the settings of the operating system,
    • the specified parameters (with the defined days and months).

If this parameter is not specified, the DD/MM/YYYY HH:mm:SS:CC format is used by default.
Remarks

Validity of date time

The validity of the date and time passed as parameters is checked. A fatal error message is displayed if the date time is invalid. You can check the validity of a date time using DateTimeValid. The date time storage format allows you to store date times between 01/01/0001 00:00:00 and 12/31/9999 11:59:59:99 PM.
WLanguage functions and properties make precise calculations on date times from January 1, 1583 00:00:00:00.

Date time format

DateTimeToString is used to format a datetime returned by RealToDateTime or SysDateTime. The result can be assigned to a text control, for example.
To get the date time in another format, you must use the following functions: Right, Left, Middle, etc.

Special case: <Format> is not specified

The language options specified for dates and times in the project description are used if no specific format is defined.
To display the linguistic options of the project:
  1. Open the project description: on the "Project" tab, in the "Project" group, click "Description".
  2. Select the "Language" tab.
For example:
  • if the project uses the linguistic options of Windows for the dates, the days of the week and the months will start with an Uppercase character on a computer running Windows in English.
  • if the project uses specific parameters for the dates for one or more languages (custom name of the day or month, etc.), these parameters will be taken into account for the specified language.
Component: wd290std.dll
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/30/2022

Send a report | Local help