Announcements
I am wanting to input a date in a date picker using a text box for month, day, an year. how would I go about doing this?
Hi @colbyturybury ,
For that you can use the Month(), Day() and Year() functions:
txtDay.Text = Day(DatePicker1.SelectedDate) txtMonth.Text = Month(DatePicker1.SelectedDate) txtYear.Text = Year(DatePicker1.SelectedDate)
Where do I place this code?
For the Text property of the label that shows the Day value:
Day(DatePicker1.SelectedDate)
For the Text property of the label that shows the Month value:
Month(DatePicker1.SelectedDate)
For the Text property of the label that shows the Year value:
Year(DatePicker1.SelectedDate)
You have it backwards. I want to type the month/day/year in their own respective text boxes and that populate the date picker.
In that case set the DefaultDate property of the DatePicker to:
DateValue($"{txtDay.Text}/{txtMonth.Text}/{txtYear.Text}")
txtDay is the TextInput that has the Day value, etc.
The year works but the day and month do not. I put in today's date and the resulting date is 11/17/2023 even though I put 01 in month 11 in day and 2023 in the year.
That is because the DateValue function by default use the language from the current user's settings. You can override it to ensure that strings are interpreted properly. For example, "10/1/1920" is interpreted as October 1st in "en" and as January 10th in "fr".
https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-datevalue-timevalue#description
An easier way though is:
Date( txtYear.Text, txtMonth.Text, txtDay.Text )
That worked! I could have sworn I had used this syntax but evidently not. Thankyou for the help!!!
Glad to read your issue got addressed. Can you please click the "Accept as Solution" button on the post that has resolved your issue for the benefit of other members of the community?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our community stars!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
WarrenBelz 305 Most Valuable Professional
11manish 212
Valantis 167