cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TimoMigchielsen
Post Prodigy
Post Prodigy

Setting a variabele to a time value

Hello!

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?


----------------------------------------------------
Edit:
----------------------------------------------------

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))
13 REPLIES 13
v-siky-msft
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.

Snipaste_2020-06-30_09-59-07.png

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

Set(SelectedDate, Today ())

Hope this helps.

Sik

Variabele:
https://gyazo.com/f1313bf76613a57008ab795924f9529e

Definitions:
https://gyazo.com/5a9eaac6a100a1d2923245167a1cb843

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:

UpdateContext({SelectedDate:Today()})

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

Reference: UpdateContext function 

Hope this helps.

Sik

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 😀

UpdateContext({SelectedDate:Today(),
StartDate: Today() - Weekday(Today()) + 1}))

Helpful resources

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