Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

Setting a variabele to a time value


I am having a calender app and I want to have a home function. I have a value SelectedDate which basically needs to be set to todays date. 


The SelectedValue is formatted like this: 6-29-2020 00:00:00      (month, day, year, hours, minutes, seconds

This is what I've tried on the onselect of an icon, but no success: 


Set(SelectedDate, Text(Today (),"[$-en-US]m-dd-yyyyy hh:mm:ss"))


The output of this formula below =  6-29-2020 00:00:00 


Text(Today (),"[$-en-US]m-dd-yyyyy hh:mm:ss")


Why is it not working?


I just realised it might be too hard to do this, as I also need to re-do the selection of the month & days, not only the selectedvalue. 

I found this code on another calender app, but I got no idea on how to implement it:

/*resets calendar view and date selection to today*/
Set(_dateSelected, Today());         
Set(_firstDayOfMonth, DateAdd(Today(), 1 - Day(Today()), Days));         
Set(_firstDayInView, DateAdd(_firstDayOfMonth, -(Weekday(_firstDayOfMonth) - 2 + 1), Days));         
Set(_lastDayOfMonth, DateAdd(DateAdd(_firstDayOfMonth, 1, Months), -1, Days))
Community Support
Community Support

Hi @TimoMigchielsen ,


Actually, I can't get what is your issue. Could you please elaborate more?

What is the error message on Set(SelectedDate) formula? What is the type of SelectedDate?

I just found the SelectedDate variable is Date type, but your code tried to assign Text to it, so there is a incompatibility problem, right? Kindly show the Variable Definitions formulas of SelectedDate as shown below.


Please try this code in your case to see if the issue is fixed.

Set(SelectedDate, Today ())

Hope this helps.




When I try your code, it does not change SelectedData too


@v-siky-msft @eka24 

Hi @TimoMigchielsen ,


It seems that the SelectedDate is a context variable. It is only scoped to a screen, which means that you can't build a formula that refers to a context variable on another screen. If you've used another programming tool, you can think of a context variable as similar to a local variable. Use the Set function to work with global variables that are available throughout your app. 

It is not allowed to define a variable as context and global at the same time, they cannot be mixed.


Hence, if the variable scope is only in a screen, please try to this code:


If not, please re-define all SelectedDate variable to a Global Variables by Set function.

Reference: UpdateContext function 

Hope this helps.


View solution in original post

Ah I see, thank you! @v-siky-msft 

I changed the code to this so it also goes back to the startdate 😀

StartDate: Today() - Weekday(Today()) + 1}))

Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,740)