Hi everybody,
I'm here since I have a little problem with the Datetimepicker Form.
I use PowerShell Studio 2014 and I can't fix the default value of an Datetimepicker object named "expirationDate" to the current date.
I've tried to set this one with these commands :
1) $expirationDate.Value.Date = [system.datetime](Get-Date -format )
2) $expirationDate.Value = Get-Date -format g
3) $expirationDate.Value = [system.datetime](Get-Date -format g)
But none match.
On the Designer of Powershell Studio, when the Datetimepicker object is selected, I can't choose a dynamic variable "current date" on the parameter "value". I don't know how to do that. I've searched a long time on the internet but nobody talk about that.
Did someone have a solution for this issue?
Best regards .
Change datetimepicker value to the 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.
Re: Change datetimepicker value to the current date
In case you don't realize this the default value of the DTP is todays date.
If you want to reset to the original date then it takes a couple of more steps.
If you want to reset to the original date then it takes a couple of more steps.
Re: Change datetimepicker value to the current date
jvierra wrote:It is a date not a str4ing.
$expirationDate.Value=[system.datetime]::Now
Thanks you ! I have read the Get-Date cmdlet library and I haven't seen before that it return a datetime value when we just use get-date cmd and a string when we add a format argument to this one.
I think that I have founded the solution for my problem. When we use a custom format for DTP the default value isn't today with powershell studio GUI. I think that it was my problem. Now it works by clearing the custom format.
Thanks for your answer,
best regards.
Re: Change datetimepicker value to the current date
When you format a date it returns a string. When you just ask it for a date you get a date object.
If you want to display a special date format then use the datepicker format property to set the format. Do not use get-Date.
Always inspect the object type and look at the property types when using PowerSHell.
$datepicker1.Value.GetType()
(Get-Date).GetType()
(Get-Date -format g).GetType()
Now you can see what matches and what doesn't.
If you want to display a special date format then use the datepicker format property to set the format. Do not use get-Date.
Always inspect the object type and look at the property types when using PowerSHell.
$datepicker1.Value.GetType()
(Get-Date).GetType()
(Get-Date -format g).GetType()
Now you can see what matches and what doesn't.
Re: Change datetimepicker value to the current date
jvierra wrote:When you format a date it returns a string. When you just ask it for a date you get a date object.
If you want to display a special date format then use the datepicker format property to set the format. Do not use get-Date.
Always inspect the object type and look at the property types when using PowerSHell.
$datepicker1.Value.GetType()
(Get-Date).GetType()
(Get-Date -format g).GetType()
Now you can see what matches and what doesn't.
Thanks you so much for your help !
Best regards !