I wanted to understand how to work with dates in PowerApps. So I challenged myself to try out all PowerApps date functions. I wanted to have an overview of what can be achieved and how it can be achieved.
In this post you find short explanations of every date related function in PowerApps. I always provide examples of the usage of the functions, since I believe this way you learn the fastest.
Let me know, if I missed something or something is wrong.
PowerApps Date Functions
Calendar
The Calendar functions helps you display calendar information for the user of your app in the user’s locale.
Syntax
Calendar.MonthsLong()
Calendar.MonthsShort()
Calendar.WeekdaysLong()
Calendar.WeekdaysShort()
Example Calendar.MonthsLong()
Calendar.MonthsLong() // for locale 'en-US'
=> [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ]
Example Calendar.MonthsShort()
Calendar.MonthsShort() // for locale 'en-US'
=> [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
Example Calendar.WeekdaysLong()
Calendar.WeekdaysLong() // for locale 'en-US'
=> [ "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" ]
Example Calendar.WeekdaysShort()
Calendar.WeekdaysShort() // for locale 'en-US'
=> [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
Clock
The Clock functions helps you display time information for the user of your app in the user’s locale.
Syntax
Clock.AmPm()
Clock.AmPmShort()
Clock.IsClock24()
Examples Clock.AmPm()
Clock.AmPm() // for locale 'en-US'
=> [ "AM", "PM" ]
Examples Clock.AmPmShort()
Clock.AmPmShort() // for locale 'en-US'
=> [ "A", "P" ]
Examples Clock.IsClock24()
Clock.IsClock24() // for locale 'en-US'
=> false
Date
To create a date for a certain year, month and day, use the Date function.
Syntax
Date( Year, Month, Day )
Parameters
- Year (mandatory): Year of the created date.
- Month (mandatory): Month of the created date.
- Day (mandatory): Day of the created date.
Return value
- The date for the given year, month and day.
Examples
Date(2022,1,23)
=> '1/23/2022'
DateAdd
To add or subtract time (Days, hours, month,…) to a date, use the PowerApps DateAdd function. For subtraction simply provide negative values to add.
Syntax
DateAdd( DateTime, Addition [, Units ] )
Parameters
- DateTime (mandatory): The date where the addition or subtraction should be executed on.
- Addition (mandatory): Number value to add/subtract time to date based on unit.
- Units (optional): Milliseconds, Seconds, Minutes, Hours, Days, Months, Quarters, Years (default: Days)
Return value
- The resulting date of the addition/subtraction.
Examples – PowerApps DateAdd
DateAdd( Now(), 5 )
=> 5 days from now (Note: default unit is days)
DateAdd( Now(), 5 , Minutes)
=> 5 minutes from now
DateAdd( Now(), -1 , Hours)
=> 1 hour ago
DateDiff
To calculate the time difference between two dates use DateDiff.
Syntax
DateDiff( StartDateTime, EndDateTime [, Units ] )
Parameters
- StartDateTime (mandatory): The date from which the difference is calculated.
- EndDateTime (mandatory): The date to which the distance is calculated.
- Units (optional): Milliseconds, Seconds, Minutes, Hours, Days, Months, Quarters, Years (default: Days)
Return value
- The numeric distance in the provided unit.
Examples – PowerApps DateDiff
DateDiff(Today(), Now(), Minutes); // Minutes past since beginning of day
=> 659 for 10:59 am
DateTimeValue
To convert a string with date and time to a date time value use the PowerApps DateTimeValue function.
Syntax
DateTimeValue( String [, Language ])
Parameters
- String (mandatory): The string that needs to be converted to a datetime value.
- Language (optional): The language that should be used for the conversion. If not set the user’s language is used as default. (see language tags here)
Allowed date formats for the string parameter
It’s obvious that the string conversion to date only works, when the strings follows a date pattern accepted by the function. Here are the pattern that do work:
- 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
Return value
- The date and time value for the given string.
Examples
DateTimeValue("05/11/2022 20:58:00")
=> May 11, 2022 8:58 PM
DateTimeValue("05/11/2022 20:58:00","de-DE")
=> November 5, 2022 8:58 PM
DateValue
To convert a date string to a date value use the DateValue function.
Syntax
DateValue( String [, Language ])
Parameters
- String (mandatory): The string that needs to be converted to a date value.
- Language (optional): The language that should be used for the conversion. If not set the user’s language is used as default. (see language tags here)
Allowed date formats for the string parameter
It’s obvious that the string conversion to date only works, when the strings follows a date pattern accepted by the function. Here are the pattern that do work:
- 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
Return value
- The date value for the given string.
Examples
DateValue("05/11/2022")
=> May 11, 2022
DateValue("05/11/2022","de-DE")
=> November 5, 2022
Day
Returns the number of the day of the given date with time.
Syntax
Day( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the day should be returned.
Return value
- The number of the day of the month. A value between 1 and 31.
Examples
Day(Now())
=> Sample return '14' for Sat May 14th, 2022
Hour
Returns the number of the hour of the given date with time.
Syntax
Hour( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the hour should be returned.
Return value
- The number of the hour of the day. A value between 0 and 23.
Examples
Hour(Now())
=> Sample return '11' for 11 AM
IsToday
Checks for a given date if it is today or not.
Syntax
IsToday( DateTime )
Parameters
- DateTime (mandatory): The date for which should by evaluated if it is today or not.
Return value
- true: if given date is today
- false: if given date is NOT today
Examples
IsToday( Now() )
=> true
IsToday( DateAdd(Now(),24,Hours) )
=> false
Minute
Returns the number of the minute of the given date with time.
Syntax
Minute( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the minute should be returned.
Return value
- The number of the minute of the hour. A value between 0 and 59.
Examples
Minute(Now())
=> Sample return value '27' for 08:27 AM
Month
Returns the number of the month of the given date with time.
Syntax
Month( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the month should be returned.
Return value
- The number of the month of the hour. A value between 1 and 12.
Examples
Month(Now())
=> Sample return value '7' for July
Now
Now does what you expect. It returns the date and time for now.
Syntax
Now()
Return value
- The current date and time.
Examples
Now()
=> Sample return '3/22/2022 12:23 PM'
Second
Returns the number of the second of the given date with time.
Syntax
Second( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the second should be returned.
Return value
- The number of the second of the minute. A value between 0 and 59.
Examples
Second(Now())
=> Sample return value '58' for 08:00:58 AM
Time
Creates a time for the given, hour, minute and seconds.
Syntax
Time( Hour, Minute, Second )
Parameters
- Hour (mandatory): A number for the needed hours ( from 0 (12:00 AM) to 23 (11:00 PM)).
- Minute (mandatory): A number for the needed minutes (0 to 59).
- Second (mandatory): A number for the needed secondes(0 to 59).
Return value
- The time for the given values.
Examples
Time(15,23,58)
=> 3:23 PM
TimeValue
To convert a time string to a time value use the TimeValue function.
Syntax
TimeValue( String [, Language ])
Parameters
- String (mandatory): The string that needs to be converted to a time value.
- Language (optional): The language that should be used for the conversion. If not set the user’s language is used as default. (see language tags here)
Return value
- The time value for the given string.
Examples
TimeValue("3:23 PM")
=> 3:23 PM
TimeValue("3:23 PM","de-DE")
=> 3:23 PM
TimeZoneOffset
The TimeZoneOffset function returns the number of minutes between the user’s local time and UTC (Coordinated Universal Time).
Syntax
TimeZoneOffset( [ DateTime ] )
Parameters
- DateTime (optional): Date and time value for which to return the offset to UTC should be calculated. (default: user’s current date/time is used).
Return value
- The number of minutes between the user’s local time and UTC.
Examples
The most common use case for the TimeZoneOffset is probably to convert a local time to UTC and vice versa.
TimeZoneOffset()
=> -120
Converting to UTC and converting from UTC
// Convert now to UTC
DateAdd( Now(), TimeZoneOffset(), Minutes )
// Convert UTC to local date time
DateAdd(
DateTimeValue("05/11/2022 20:58:00"),
-TimeZoneOffset(DateTimeValue("05/11/2022 20:58:00")),
Minutes
)
Today
The Today function return the date of today.
Syntax
Today()
Return value
- The date of today.
Examples
Today() // in case today is the 17th May 2022
=> May 17, 2022
Weekday
The Weekday function returns the number for the day within the week. By default the week starts on Sunday, but you can modify the start of the week to your needs.
Syntax
Weekday( DateTime [, WeekdayFirst ] )
Parameters
- DateTime (mandatory): The date with time for which the second should be returned.
- WeekdayFirst (optional): The Excel code specifying which at what day the week begins. (default value is Sunday, in case you do not provide another day)
For the WeekdayFirst parameter you can provide the first day of the week by using the StartOfWeek enumeration. I advise doing so, because it is easier to understand for the reader of your code.
- StartOfWeek.Sunday (ExelCode 1,17)
- StartOfWeek.Monday (ExelCode 2,11)
- StartOfWeek.MondayZero (ExelCode 3) [This changes the return value range from 0-6 instead of 1-7]
- StartOfWeek.Tuesday (ExelCode 12)
- StartOfWeek.Wednesday (ExelCode 13)
- StartOfWeek.Thursday (ExelCode 14)
- StartOfWeek.Friday (ExelCode 15)
- StartOfWeek.Saturday (ExelCode 16)
Return value
- The number of the day within the week. (value from 1 – 7)
Examples
Weekday(Now())) // if now is Tuesday
=> 3
Weekday(Now(),StartOfWeek.Monday) // if now is Tuesday
=> 2
WeekNum
The WeekNum function returns the number of the week within a year (value between 1 and 54).
Syntax
WeekNum(DateTime [, StartOfWeek ])
Parameters
- DateTime (mandatory): The date for which the week number should be returned.
- StartOfWeek (optional): The Excel code specifying which at what day the week begins. (default value is Sunday, in case you do not provide another day)
For the StartOfWeek parameter you can provide the first day of the week by using the StartOfWeek enumeration. I advise doing so, because it is easier to understand for the reader of your code.
- StartOfWeek.Sunday (ExelCode 1,17)
- StartOfWeek.Monday (ExelCode 2,11)
- StartOfWeek.Tuesday (ExelCode 12)
- StartOfWeek.Wednesday (ExelCode 13)
- StartOfWeek.Thursday (ExelCode 14)
- StartOfWeek.Friday (ExelCode 15)
- StartOfWeek.Saturday (ExelCode 16)
Return value
- The number of the week within a year. (1th January is week 1; The value range is from 1 to 54)
Examples
WeekNum(Date(2022,1,1)) // first week in 2022
=> 1
WeekNum(Date(2022,12,31)) // last week in 2022
=> 53
WeekNum(Date(2022,1,1),StartOfWeek.Monday)
=> 1
Year
Returns the number of the year of the given date with time.
Syntax
Year( DateTime )
Parameters
- DateTime (mandatory): The date with time for which the year should be returned.
Return value
- The number of the year of the given date (staring at 1900).
Examples
Year( Now() )
=> 2022