cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wayne1
Level: Power Up

New variable that combines Date and Time variables

I want to create a new variable that will be the date picked from a date picker and the time from a dropdown.

 

The datepicker.SelectedDate is already in Date format, but the time from the dropdown is a text string 

["9:00 AM","9:30 AM","10:00 AM..."4:30 PM","5:00 PM"]

 

I want to set a new variable on the press of a button to combine the two, preferably in Date/Time format. 

 

I've tried setting the date to text and concatenating that string with the time string then converting that back to date/time, I've also tried  

Set(NewDateTimeVariable, Datepicker.SelectedDate + TimeValue(Dropdown.Selected.Value))

but I get the error "Incompatible type. We can't evaluate your formula because the context variable types are incompatible with the types of values in other places in your app."

 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: New variable that combines Date and Time variables

I would suggest the following:

 

Set(
     NewDateTimeVariable, 
     DateTimeValue(
          Datepicker.SelectedDate 
          & " " &  
          TimeValue(Dropdown.Selected.Value)
     )
)

I think the "+" in your original formula is causing PowerApps to try and add, rather than concatenate, the two values. By using & " " & instead, it creates a text string which the DateTimeValue function is able to use. Let me know how that works for you.

*edit* Premature submission! Testing the above code worked for me as far as creating a DateTime value. If that doesn't work, you may need to look at the NewDateTimeVariable to see if it is expecting something else using View -> Variables and selecting NewDateTimeVariable from the list and looking at the Definitions and Uses tabs.

View solution in original post

4 REPLIES 4
Super User
Super User

Re: New variable that combines Date and Time variables

I would suggest the following:

 

Set(
     NewDateTimeVariable, 
     DateTimeValue(
          Datepicker.SelectedDate 
          & " " &  
          TimeValue(Dropdown.Selected.Value)
     )
)

I think the "+" in your original formula is causing PowerApps to try and add, rather than concatenate, the two values. By using & " " & instead, it creates a text string which the DateTimeValue function is able to use. Let me know how that works for you.

*edit* Premature submission! Testing the above code worked for me as far as creating a DateTime value. If that doesn't work, you may need to look at the NewDateTimeVariable to see if it is expecting something else using View -> Variables and selecting NewDateTimeVariable from the list and looking at the Definitions and Uses tabs.

View solution in original post

wayne1
Level: Power Up

Re: New variable that combines Date and Time variables

Thanks wyotim,

 

It's strange because I set the dropdown.selected.value to be a variable and the datepicker.SelectedDate to be another variable and when I use the variable names in the exact same place it fails, but when I directly reference the selected values instead of their equivalent set variables it works.  

 

Oh well, that solves my problem.  Thanks again!

 

 

Super User
Super User

Re: New variable that combines Date and Time variables

@wayne1That is a bit strange. Glad the direct references worked though! 

muralikrishna00
Level: Powered On

Re: New variable that combines Date and Time variables

Hi @wayne1 

 

Screen shots please ...?

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,156)