web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Lookup on short date
Power Apps
Unanswered

Lookup on short date

(0) ShareShare
ReportReport
Posted on by 134

I have found a few topics on this subject, a lot of them with solutions like this one-:

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Trying-to-filter-or-lookup-on-a-date-field/td-p/134465

 

In short it says to either

A. have a calcualted field in my database table which is just the date converted to a int in the yyyymmdd format

B. Convert the result of my variable and my database value to an identical text value Ex:
     Text(DatabaseDate,"[$-en-US]mm-dd-yyy]") = Text(PowerappsDate,"[$-en-US]mm-dd-yyy]")

 

This is because while my database is storing the value as a "Date" value (which is a short date, date with no time), it seems that all date variables in powerapps return a datetime (often with 12:00:00).  Even the Date() function.

 

Is there still no other way to solve this(have powerapps return a date, not a datetime)? For a variety of reasons modifying the tables i need to in this case is super unattractive, but I suspect that as the dataset grows converting date values to text/datetime is going to eventually kill the lookup (it's giving a warning in powerapps that this could happen).

 

 

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    Try one of these and see if anything works:

     

    Value(Today())/86400000+Date(1970,1,1)

    Value(Value(Today())/86400000+Date(1970,1,1))

    Text(Value(Today())/86400000+Date(1970,1,1))

     

    What's your data source? The reason I ask is that if the data type on your source is date and you feed it a datetime I would think it would just strip the time automatically.

  • dungar Profile Picture
    134 on at

    Not sure how you want me to apply those? They all return a rather large int, which doesn't help as now i have to convert the SQL side and the powerapps date selector side.

     

    It's a MS SQL Server table with a column that's type "Date". 

     

    Might help if i add the use case:

     

    I'm attempting to take a location (from a combobox, which displays a string value that's got an int tied to it) and a date (from a date picker) and then look them up in my database (location column, int, and date column, date).  If there's no existing record, I want to allow the user to continue as that means their entry won't duplicate data.

     

    In order to do this i'm attempting to take the selected date and set it to a variable (ditto on the combo box, but that might be a separate topic as it's being set as a table). I then want to perform a lookup based on that variable.  If it returns nothing, great, otherwise throw an error.  The issue of course is that it ALWAYS returns nothing because it's a datetime in powerapps and a date in my database, so i have to somehow modify the database result, which then throws a warning that this may not work on larger subsets of data.

     

    In both cases this is coming down to the fact that there doesn't seem to be a way to cast data in powerapps?  If i could just tell it that it's a date, not a datetime, or an int, not a table with a single int value, I could do my comparisons and move on.  Is there really no easy way to do that?

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    I see what you're going for. Yeah, my previous reply would be no help here. You could tweak your view or stored procedure to accept datetimes using some logic like this example:

     

     

     declare @powerAppsValue datetime = '12/9/2019 12:00:00 AM'
    
     with DataTable as
     (
     Select CAST('12/9/2019' as date) TestDate
     )
    
     select * from DataTable where TestDate = CAST(@powerAppsValue as date) 

     

     

    Or possibly clean it up in Flow like this solution:

    https://powerusers.microsoft.com/t5/Building-Flows/Convert-date-time/td-p/65725

  • SeanTambling Profile Picture
    176 on at

    I had your same problem. I asked and asked and looked and finally i asked the right person @Shanescows  , and Shane Young sent me an image, i've attched it below. Essentially, go to File, Settings, Advance Settings and scroll down and enable Enhanced SQL Server Connector. Once I did, i set the date picker to Local and the date started functioning correctly. Hope this will work for you as well.

  • SeanTambling Profile Picture
    176 on at

    Oh jeeze, i really need to read better. I got so excited that i might could pass along some info that I didn't read your post well. Not sure my solution will help you or not tbh. Worth a try if nothing else helps.

  • dungar Profile Picture
    134 on at

    Ugh that's rough. 

     

    I did manage to figure out my combobox issue was because I was using SelectedItems instead of Selected, but having to make modifications to our database or delve into flow in order to accommodate powerapps inability to use short date is a pretty big problem for us logistically.

     

    I can think of several ways to do it, but there's quite a lot of data we were hoping to get front ends on through powerapps, and while adding a datetime to the datetable and building views is doable, it seems utterly absurd that it's necessary.  Oh well.

     

  • Community Power Platform Member Profile Picture
    on at

    It just clicked that you're using a datepicker and we can leverage the separate values in that control.

    Try this?

    Text(Month(DatePicker1.SelectedDate) & "/" & Day(DatePicker1.SelectedDate) & "/" & Year(DatePicker1.SelectedDate))

     

    If that works, you can add this to the OnChange function for the date picker (and the OnVisible for the form so it picks up the initial value):

     

    Set(DatePickerValue,Text(Month(DatePicker1.SelectedDate) & "/" & Day(DatePicker1.SelectedDate) & "/" & Year(DatePicker1.SelectedDate)))

  • dungar Profile Picture
    134 on at

    I don't think this solves the issue.

     

    For example the date i'm testing is stored in the SQL database as "2019-11-07".

     

    So i could do-

     

    DateVar = Text(Year(PowerAppsDate.SelectedDate) & "-" & Month(PowerAppsDate.SelectedDate) & "-" & Day(PowerAppsDate.SelectedDate))

     

    and then try:

     

    Loookup(SQLTable, Text(SQLDate) = DateVar)

     

    but

     

    1. I need to add more code to the Datevar to get it to 07 instead of 7.  Finicky but not a dealbreaker.

    2. I still have to modify the SQLDate value by putting a Text() function around it, which then means i get the delegate warning about it possibly failing on a large enough dataset.  As this is a long term solution I can't risk it eventually just dying, so it seems i'm back to "rework my database because powerapps doesn't believe in short dates"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard