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

Lookup on short date

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

 

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
EricLott
Level 10

Re: Lookup on short date

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

View solution in original post

8 REPLIES 8
EricLott
Level 10

Re: Lookup on short date

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
Level: Powered On

Re: Lookup on short date

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?

EricLott
Level 10

Re: Lookup on short date

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

View solution in original post

SeanTambling
Level: Powered On

Re: Lookup on short date

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.

Highlighted
SeanTambling
Level: Powered On

Re: Lookup on short date

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
Level: Powered On

Re: Lookup on short date

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.

 

EricLott
Level 10

Re: Lookup on short date

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
Level: Powered On

Re: Lookup on short date

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"

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,367)