DateValue, TimeValue, and DateTimeValue functions

Applies to: Canvas apps Desktop flows Model-driven apps Power Platform CLI

Converts date, time, or both in a string to a date/time value.

Description

  • DateValue function converts a date string (for example, "10/01/2014") to a date/time value.

  • TimeValue function converts a time string (for example, "12:15 PM") to a date/time value.

  • DateTimeValue function converts a date and time string (for example, "January 10, 2013 12:13 AM") to a date/time value.

DateValue function ignores any time information in the date string, and the TimeValue function ignores any date information in the time string.

Note

The DateValue, TimeValue, and DateTimeValue functions by default use the language from the current user's settings. You can override it to ensure that strings are interpreted properly. For example, "10/1/1920" is interpreted as October 1st in "en" and as January 10th in "fr".

Dates must be in one of these formats:

  • MM/DD/YYYY or MM-DD-YYYY
  • DD/MM/YYYY or DD-MM-YYYY
  • YYYY/MM/DD or YYYY-MM-DD
  • MM/DD/YY or MM-DD-YY
  • DD/MM/YY or DD-MM-YY
  • DD Mon YYYY
  • Month DD, YYYY

To convert from numeric date, month and year components, read Date.
To convert from numeric hour, minute and second components, read Time.

For more information, read:

Syntax

DateValue( String [, Language ])
DateTimeValue( String [, Language ])
TimeValue( String [, Language ])

  • String - Required. A text string that contains a date, time, or combination date and time value.
  • Language - Optional. A language string, such as would be returned by the first two characters from the Language function. If not provided, the language of the current user's settings is used.

DateValue( Untyped )
DateTimeValue( Untyped )
TimeValue( Untyped )

  • Untyped - Required. Untyped object that represents a date or time. Acceptable values are dependent on the untyped provider. For JSON, the untyped object is expected to be a JSON string that contains a date and time in ISO 8601 format. Dates or times in other formats will result in an error. Consider converting such values to Text first, then to a date or time. Keep in mind that time zones and locale-related formats are important considerations when communicating with external systems.

Examples

DateValue

If you type 10/11/2014 into a text-input control named Startdate, and then set the Text property of a label to these formulas:

  • Convert a date from a string in the user's locale and show the result as a long date.

    Text( DateValue( Startdate.Text ), DateTimeFormat.LongDate )
    

    Device set to en locale shows the label as Saturday, October 11, 2014.

    Note

    You can use several options with the DateTimeFormat enum. To display a list of options, type the parameter followed by a dot or period (.) in the formula bar or check Text function reference.

  • Convert date from a string in the French locale and show the result as a long date. In this example, the months and day of the month are interpreted differently from English.

    Text( DateValue( Startdate.Text, "fr" ), DateTimeFormat.LongDate )
    

    Device set to en locale shows the label as Monday, November 10, 2014.

If you typed October 20, 2014 instead:

  • Convert a date from a string in the user's locale and calculate the difference between two days, in days

    DateDiff( DateValue( Startdate.Text ), Today() )
    

    Device set to en locale shows the label as 9, indicating the number of days between October 11 and October 20. The DateDiff function can also show the difference in months, quarters, or years.

DateTimeValue

If you typed 10/11/2014 1:50:24.765 PM into a text-input control named Start, and then set the Text property of a label to the following formula:

  • Convert both a date and time string in the current locale.

    Text( DateTimeValue( Start.Text ), DateTimeFormat.LongDateTime )
    

    Device set to en locale shows the label as Saturday, October 11, 2014 1:50:24 PM.

    Note

    You can use several options with the DateTimeFormat enum. To display a list of options, type the parameter followed by a dot or period (.) in the formula bar or check Text function reference.

  • Convert both a date and time string in the French locale. Month and day of the month are interpreted differently.

    Text( DateTimeValue( Start.Text, "fr"), DateTimeFormat.LongDateTime )
    

    Device set to en locale shows the label as Monday, November 10, 2014 1:50:24 PM.

  • Convert both a date and time string in the user's locale, and display the result with a fractional second.

    Text( DateTimeValue( Start.Text ), "dddd, mmmm dd, yyyy hh:mm:ss.fff AM/PM" )
    

    Device set to en locale shows the label as Saturday, October 11, 2014 01:50:24.765 PM.

    As an alternative, you can specify hh:mm:ss.f or hh:mm:ss.ff to round the time to the nearest 10th or 100th of a second.

TimeValue

Name a text-input control FinishedAt, and set the Text property of a label to this formula:

If( TimeValue( FinishedAt.Text ) < TimeValue( "5:00:00.000 PM" ),
    "You made it!",
    "Too late!"
)
  • If you type 4:59:59.999 PM in the FinishedAt control, the label shows "You made it!"
  • If you type 5:00:00.000 PM in the FinishedAt control, the label shows "Too late!"