cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Ali_Nawaz
Level: Powered On

SQL Date type comparison in powerapps

Hi PowerUsers, 

I am trying to filter an SQL table on the basis of date. 
In SQL i have column named "AttendanceDate" with data type as Date.
Screenshot_8.png


When i try to filter data in powerapps on the basis of this column I am receiving this error.
"We cannot apply operator < to types DateTimeZone and Date"      (Check Screenshot Below)  


Screenshot_1.png

Is there a fix for this or any workaround. 
I need this date comparison to work, its an essential part for my App. 


Looking forward to quick response. 


Best Regards, 
Ali Nawaz

1 REPLY 1
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: SQL Date type comparison in powerapps

As you noticed, you cannot compare against Date columns in SQL directly. There is a workaround (described in https://docs.microsoft.com/en-us/connectors/sql/), where you can create a calculated column in your SQL table based on that date of type INT that represents the date value, something along the lines of

ALTER TABLE TV_AttendanceTable
ADD AttendanceDateAsInt AS YEAR(AttendanceDate) * 10000 + MONTH(AttendanceDate) * 100 + DAY(AttendanceDate)

In your app you can then update your expression to use that new column:

Sort(
    Filter(
        Filter('[dbo].[TV_AttendanceTable]', WorkerNumber = WorkerRecord.PERSONNELNUMBER),
        AttendanceDateAsInt <= Year(DateValue(PPEndDate)) * 10000 + Month(DateValue(PPEndDate)) * 100 + Day(DateValue(PPEndDate)),
        AttendanceDateAsInt >= Year(DateValue(PPStartDate)) * 10000 + Month(DateValue(PPStartDate)) * 100 + Day(DateValue(PPStartDate)),
        PayCycleID = First(PayCycColl).PayCycleId),
    AttendanceDateAsInt,
    Descending)

Hope this helps!

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,672)