New-UDDatePicker issue with format dd.MM.yyyy HH:mm:ss

Hello World

I’m trying to create a form with two datepickers.

The first line (12. of December) works fine but the second line (13. of December) produces the error message below:

New-UDDatePicker -Label "xyy" -Value "12.12.2020 05:00:00"
New-UDDatePicker -Label "xyy" -Value "13.12.2020 05:00:00"

Cannot process argument transformation on parameter 'Value'. Cannot convert value "13.12.2020 22:11:11" to type "System.DateTime". Error: "String was not recognized as a valid DateTime.

I tried a lot of different methods to manipulate, parse and convert the date format. No success. I tried to split the initial string and to recreate the date string with join. No success.

It seems that somehow days with number higher then 12 are not accepted.

What I’m missing?

It certainly seems like it’s using US format MM.dd.yyyy for some reason.

Did you try using DateTime.ParseExact?

$Dec13 = [DateTime]::ParseExact('13.12.2020 05:00:00', 'dd.MM.yyyy h:mm:ss', $null)
New-UDDatePicker -Label "xyy" -Value "13.12.2020 05:00:00"

I tried that too and in that case I get validation error in red Invalid Date Format below datepicker field. Kinda weird.

Seems like we might have a bug in the date picker that is trying to enforce a particular date format. I’ll open an issue to see if we can get this resolved.

Thank you adam. Just wanted to make sure I’m not missing something. We will see.

Hi @nelkasov just so you know there is another component out there:-
https://marketplace.universaldashboard.io/Dashboard/UniversalDashboard.UDSelectDateTime
There is an example in the README hope this helps.

Thanks for that @psDevUK, will try it.
I’m working in a sandbox without internet access. Is there a way to install UDSelectDateTime manually? I can transfer files to the server but no download from internet is allowed.

As it is hosted on the powershell gallery you will need a machine with internet access to obtain it. However if you can copy a file to your environment from a trusted source, just copy the module and paste it in the modules directory…

1 Like

I got it working with default DatePicker component in this order:

  1. Initialize with a date the component likes which is for example 01.01.2021 (day <= 12)
New-UDDatePicker -Id 'startDate' -Value '01.01.2021 23:59:59'
  1. Set value to anything you want
Set-UDElement -Id 'startDate' -Properties @{
    Value = '31.12.2021 00:00:00'
}

Thanks!

1 Like