cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Digital
Responsive Resident
Responsive Resident

Filter a gallery by date for SQL column of type datetime2

I would like to filter my gallery by an SQL datetime2 column called DueDate

 

I have got it to work by using the DateAdd function on the DueDate column but this results in a delegation warning.

 

Filter(
    '[SQLTABLE]',
    DateAdd(DueDate, TimeZoneOffset(DueDate), Minutes) = Dropdown2.Selected.Result
     
)

 

I originally tried to use the DateAdd and TimeZoneOffset on my drop down of dates which is populated using the same Column.

 

Unfortunately this does not work and I can't figure out why. Have also tried this using the date picker with no luck.

Distinct(
    '[SQLTABLE]'.DueDate,
    DateAdd(DueDate, TimeZoneOffset(DueDate), Minutes)
)
   

 

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User III
Super User III

Hi @Digital 

As datetime2 is not supported in Power Apps, my approach would be to create a view and to cast your duedate column to the datetimeoffset datatype (which is supported).

CREATE VIEW vwYourView
AS
SELECT
  Column1,
  Column2,
  CAST(DueDate AS DATETIMEOFFSET) AS [DueDate]
FROM
 [SQLTable]

You can then filter this view by your DueDate column.

 

By casting to the datetimeoffset data type, you can more easily filter records against a datepicker control (without needing to covert the selected date in the date picker control to a number in yyyymmdd format), and you can also more easily use the greater than/less than operators in call to filter, whilst also overcoming the bug that I describe here.

http://powerappsguide.com/blog/post/sql-dont-let-this-datetime-bug-catch-you-out

 

View solution in original post

2 REPLIES 2
v-albai-msft
Community Support
Community Support

Hi @Digital ,

If you want to filter based on datetime2 in PowerApps, it is not supported.

The following data types cannot be used as query option predicates:

  • date
  • datetime
  • datetime2
  • smalldatetime

If you want to filter, you need to use this formula to transfer:

YEAR([date]) * 10000 + MONTH([date]) * 100 + DAY([date])

Before using above formula, you need to add a new column. For more detailed information, you can refer to the solution provided by @Michael Colbert in this thread:

https://www.powerappsug.com/communities/community-home/digestviewer/viewthread?GroupId=2243&MessageK... 

Also you can refer to this video to create a new column to keep the value from your datetime2 column.

https://www.youtube.com/watch?v=t4psUHxvI38 

Best regards,

Allen

timl
Super User III
Super User III

Hi @Digital 

As datetime2 is not supported in Power Apps, my approach would be to create a view and to cast your duedate column to the datetimeoffset datatype (which is supported).

CREATE VIEW vwYourView
AS
SELECT
  Column1,
  Column2,
  CAST(DueDate AS DATETIMEOFFSET) AS [DueDate]
FROM
 [SQLTable]

You can then filter this view by your DueDate column.

 

By casting to the datetimeoffset data type, you can more easily filter records against a datepicker control (without needing to covert the selected date in the date picker control to a number in yyyymmdd format), and you can also more easily use the greater than/less than operators in call to filter, whilst also overcoming the bug that I describe here.

http://powerappsguide.com/blog/post/sql-dont-let-this-datetime-bug-catch-you-out

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,515)