Page 1 of 1

Change datetimepicker value to the current date

Posted: Mon Jul 07, 2014 6:53 am
by adiagne
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? :roll:


Best regards :) .

Re: Change datetimepicker value to the current date

Posted: Mon Jul 07, 2014 7:00 am
by jvierra
It is a date not a str4ing.

$expirationDate.Value=[system.datetime]::Now

Re: Change datetimepicker value to the current date

Posted: Mon Jul 07, 2014 7:05 am
by jvierra
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.

Re: Change datetimepicker value to the current date

Posted: Tue Jul 08, 2014 2:38 am
by adiagne
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. :oops:

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

Posted: Tue Jul 08, 2014 5:55 am
by jvierra
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.

Re: Change datetimepicker value to the current date

Posted: Wed Jul 09, 2014 3:31 am
by adiagne
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 !