New-UDDatePicker - Unable to set date using -value

Ive logged this on github already, but thought I should check here first in case I was doing something stupid, or had missed the blindingly obvious.

Whenever I try to set the value (with -value) of a New-UDDataPicker to anything over the 12th of the month it errors with Invalid Date Format. Im assuming this is a bug to with the way it handles time formats.

Does anyone have any ideas of how this can be handled when you need to pre-populate the date picker?

New-UDDatePicker -Id 'test1' -Label 'test1' -value (Get-Date '01/01/2021')
New-UDDatePicker -Id 'test2' -Label 'test2' -value (Get-Date '12/01/2021') -Format 'dd/MM/yyyy'
New-UDDatePicker -Id 'test3' -Label 'test3' -value (Get-Date '12/01/2021')
New-UDDatePicker -Id 'test3' -Label 'test4' -value (Get-Date '13/01/2021')
New-UDDatePicker -Id 'test4' -Label 'test5' -Format 'dd/MM/yyyy' -value (Get-Date '13/01/2021')


Product: PowerShell Universal
Version: 1.5.9

it looks like its taking the date as mm/dd/yyyy thats why the error appear.

Thats correct, but since im passing it an object of type [datetime] it should be doing any required conversion itself.

Even after formatting the date manually it still errors with invalid date format

(Get-Date '13/01/2021' -Format 'MM/dd/yyyy')

look at this article New-UDDatePicker issue with format dd.MM.yyyy HH:mm:ss - #7 by nelkasov

there is a workaround.

i have found a fix so far that worked and show the format as you want “MM/dd/yyyy” or “dd/MM/yyyy”
let me know if you still need assistant and ill post how to apply the fix.

I thought I would give your New-UDSelectDateTime a go and see if that helped at all. Unfortunately it seems to be generating a RangeError when used in a form (works fine with normal [datetimes] otherwise). Can you see anything wrong with this (Hopefully im missing something wonderfully obvious)?

New-UDDashboard -Title 'NotificationDatePicker' -Content {
    New-UDSelectDateTime -Id 'NotificationDatePicker' # Works
    New-UDForm -Content {
        New-UDSelectDateTime -Id 'NotificationDatePicker' # Error (There was an error rendering component of type UD-SelectDateTime. RangeError: Invalid time value)
    } -OnSubmit {}

Cheers for that, unfortunately the work around is not working for me. Field does not get updated.


The fix i found is in the PSU code itself its not a workaround, its a change you need to make in the function code itself.

1 Like

Hello @ZHumphries thanks for giving my module a shot. I didn’t test this inside the New-UDForm however you could just add a button and get the values from that, or use the suggestion @wsl2001 has given. Or if you place it outside the New-UDForm but within the -OnSubmit read the values from the ID of the component that should work, but not sure how many other things you have on your form? I mean I have built a ton of components, I do have field text box components, then use them and a custom buttom for the submit…guess the easier option is to follow @wsl2001 advice :crossed_fingers:

look for new-uddatepicker function in c:\programdata\powershelluniversal\framework\3.2.7\material.ps1 file and replace the [String]$format = “MM/dd/yyyy”, with [String]$format,
and now you should be able to pass any format you like for the date.

1 Like