Set DateTimePicker to current date

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Locked
User avatar
kungfujedis
Posts: 1
Joined: Mon Sep 28, 2015 9:09 am

Set DateTimePicker to current date

Post by kungfujedis » Wed Dec 23, 2015 10:56 am

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?

User avatar
jvierra
Posts: 11557
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Set DateTimePicker to current date

Post by jvierra » Wed Dec 23, 2015 11:12 am

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

User avatar
dan.potter
Posts: 706
Joined: Wed Oct 08, 2014 6:02 am

Re: Set DateTimePicker to current date

Post by dan.potter » Mon Dec 28, 2015 6:20 am

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

}

Locked