cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ali_Nawaz
Helper III
Helper III

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
CarlosFigueira
Power Apps
Power Apps

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
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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (39,222)