Set DateTimePicker to current date
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- kungfujedis
- Posts: 1
- Last visit: Thu Nov 30, 2017 1:53 pm
Set DateTimePicker to current date
I want the date time picker to have the current date selected when the script is run. Currently, it always shows the date time of the last time i edited the script (aka, clicked "now" in the designer). I found this post: viewtopic.php?t=7837 ; in which it says that default behavior is already to show the current date. However, this is not what is happening in my script. I've tried setting the values at the beginning of my script with $datetimepicker.value = get-date -format d, or $datetimepicker.value = [system.datetime]::Now and other variations, but the date displayed in the form GUI does not seem to change. Suggestions?
Re: Set DateTimePicker to current date
Don't assign a value. It will show current date by default. If you set a date accidentlly hen delete the control and add it again. Do not set the date. The new control will work.
As an Alternate reset the date in the form load event.
$datetimepicker1.Value = [datetime]::Now
As an Alternate reset the date in the form load event.
$datetimepicker1.Value = [datetime]::Now
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Set DateTimePicker to current date
Set the custom format in the designer. I use this when I call the form as I'm not concerned with past dates.
$form1_Load = {
$dateTimePicker1.MinDate = Get-Date
}
$form1_Load = {
$dateTimePicker1.MinDate = Get-Date
}