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!

 

 

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

Hi @Anonymous 

 

Screen shots please ...?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,115)