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
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,784)