If you would like to upgrade to a newer long-term support version of Studio Pro, see Moving from Mendix Studio Pro 8 to 9.
Parse and Format Date Function Calls
Introduction
This document describes functions that are used to parse Date and time values from strings using a specified pattern, or to produce a string from a Date and time value.
For details on all pattern possibilities, see Class SimpleDateFormat.
parseDateTime[UTC]
Takes a string and parses it. If it fails and a default value is specified, it returns the default value. Otherwise, an error occurs. The function parseDateTime
uses the user’s time zone and parseDateTimeUTC
uses the UTC calendar.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Date | A string which contains the textual representation of a date, meaning, dd/mm/yyyy , mm/dd/yyyy , etc. |
Format | String |
Default value (optional) | Date and time |
Output
The output is described in the table below:
Value | Type |
---|---|
The parsed date or the default value if a date could not be parsed. | Date and time |
Example
The examples below illustrate which value the expression returns:
-
If you use the following input:
parseDateTime('2015-05-21', 'yyyy-MM-dd')
the output is:
The date May 21, 2015\. The time will be 12 o'clock at night because it is not specified.
-
If you use the following input:
parseDateTime('noDateTime', 'dd-MM-yyyy', dateTime(2007))
the output is:
'Mon Jan 01 00:00:00 CET 2007'
formatDateTime[UTC]
Converts the Date and time value to a string, formatted according to the format parameter. Without the format parameter, a standard format is used, which depends on the Java version and user locale. The function formatDateTime
uses the users calendar and formatDateTimeUTC
uses the UTC calendar.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Date | Date and time |
Format (optional) | String |
Output
The output is described in the table below:
Value | Type |
---|---|
A formatted representation of the Date and time value. | String |
Example
If you use the following input:
formatDateTime($object/Date1,'EEE, d MMM yyyy HH:mm:ss Z')
the output is:
'Sun, 8 Jun 2008 10:12:01 +0200'
To get ‘1987-12-31T23:59:00’, you need to concatenate two formatDateTime[UTC] functions:
formatDateTime($object/Date1,'yyyy-MM-dd') + 'T' + formatDateTime($object/Date1,'HH:mm:ss')
formatTime[UTC]
Converts the time part of Date and time value to a string in a standard format, which depends on the Java version and user locale. formatTime
uses the users calendar and formatTimeUTC
uses the UTC calendar.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Date | Date and time |
Output
The output is described in the table below:
Value | Type |
---|---|
A formatted representation of the time part of the Date and time value. | String |
Example
If you use the following input:
formatTime(dateTime(1974, 7, 2, 9, 50, 10))
the output is:
'9:50 AM'
formatDate[UTC]
Converts the date part of Date and time value to a string in a standard format, which depends on the Java version and user locale. formatDate
uses the users calendar and formatDateUTC
uses the UTC calendar.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Date | Date and time |
Output
The output is described in the table below:
Value | Type |
---|---|
A formatted representation of the date part of the Date and time value. | String |
Example
If you use the following input:
formatDate(dateTime(1974, 7, 2, 9, 50, 10))
the output is:
'7/2/74'
dateTimeToEpoch
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT to the date.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Date | Date and time |
Output
The output is described in the table below:
Value | Type |
---|---|
The number of milliseconds since January 1, 1970, 00:00:00 GMT to the date. | Integer/Long |
Example
If you use the following input:
dateTimeToEpoch(dateTime(1974, 7, 2, 9, 50, 10))
The output is:
141990610000
epochToDateTime
Creates a Datetime that represents the specified number of milliseconds since January 1, 1970, 00:00:00 GMT.
Input Parameters
The input parameters are described in the table below:
Value | Type |
---|---|
Epoch | Integer/Long |
Output
The output is described in the table below:
Value | Type |
---|---|
A Datetime that represents the specified number of milliseconds since January 1, 1970, 00:00:00 GMT. | Date and time |
Example
If you use the following input:
epochToDateTime(141990610000)
The output is:
dateTime(1974, 7, 2, 9, 50, 10)