cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kriggo15
Responsive Resident
Responsive Resident

Storing date picker as variable string

I have a variable (SubmitValue) that I'm using to store a text variable. In one case, that is coming from a dropdown, and in this case it needs to come from a date picker (DatePicker1). I'm storing it in a string variable because I'm writing it back to a varchar datatype in sql server.

 

I've set the OnChange property of the date picker to:

 

Set(SubmitValue, (DatePicker1.SelectedDate))

 

 

I also have a label set to the variable name. When I choose a date (3/10/2020), the label comes across as:

 

1583812800000

 


How do I get it to come across as the actual date selected?

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

just change your current code to the following:

Set(SubmitValue, Text(DatePicker1.SelectedDate,DateTimeFormat.ShortDate))

That will format the date as a string and prevent it from converting to Ticks 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
mdevaney
Super User
Super User

@kriggo15 

I think you can convert the number to a date like this.  Let me know if it works for you.

Date(1970,1,1) + 1583812800000/(60*60*24*1000) )

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Pstork1
Dual Super User
Dual Super User

just change your current code to the following:

Set(SubmitValue, Text(DatePicker1.SelectedDate,DateTimeFormat.ShortDate))

That will format the date as a string and prevent it from converting to Ticks 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
kriggo15
Responsive Resident
Responsive Resident

Hey there @mdevaney 


If I understood your code, I'm getting the same value:

Set(SubmitValue, DatePicker1.SelectedDate); Set(SubmitValue, Date(1970,1,1) + SubmitValue/(60*60*24*1000))


datepicker.png

@kriggo15 

Use the solution of @Pstork1 above.

kriggo15
Responsive Resident
Responsive Resident

@Pstork1 

I get an error when using your method:
datepicker2.png

Try changing the name of the variable.  It works for me without error, but it may be giving you trouble since the variable was already created with a data value rather than a string.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

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

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (5,402)