cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
wyotim
Resident Rockstar
Resident Rockstar

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
wyotim
Resident Rockstar
Resident Rockstar

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.

Anonymous
Not applicable

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!

 

 

wyotim
Resident Rockstar
Resident Rockstar

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

Hi @Anonymous 

 

Screen shots please ...?

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (1,584)