is there a setting for the date format that will use month day year. I am using the new-udinputfield -type date but every time it uses day month year.
any assistance is appreciated
pg
New-UDInput -Content {
Thanks for the reply (I appreciate that!) - I tried a few things and cant seem to get it to do anything to the $datep ā¦I think the formatting is coming from -type ādateā but I really donāt know. I tried several variations of your suggestions with no luck. but thank you - I am going to bang my head some more donāt want to go back to powershell studio. I have my own form that can select a date but vs code doesnāt support winforms assembly. thanks for the ideas and insight though
New-UDInput -Content {
.net ToString operator already support date formatting.
See : DateTime.ToString documentation for all the possibilities.
This is way better, easier and most importantly robust than using the replace operator since the default dateTime.Tostring() initial output can change depending on the system DateTime settings.
@itfranck I would normally go with this method, but for some reason this throws an errorā¦so yesterdays suggestion was taken from a powershell studio script I got, and I didnāt actually test it. Sorry @patg I didnāt mean to throw any false leads. So anyway been thinking about this, this morning and I have the following working solution:- Formatting your date
I actually tested this time in a dashboard, as mentioned I have used @itfranck way but had to get-date on the parameter before this would work else throws an error.
Thanks psDevUK and ITFranck ā¦unfortunately itās still not working.
what I noticed is that when I run the āFormatting your dateā code (as supplied above - thanks for that), I get the result for the date july 1, 2019 as 01-07-2019 but when I change the $dateformat = $var.tostring(ādd-MM-yyyyā) I get 07-01-2019. that seems fine but if I choose date july 27, 2019 it errors out with cannot convert value"27-07-2019" to type āsystem date timeā error ā27-07-2019ā was not recognized as a valid date time.
I am not sure if itās because my get-culture is en-US. not sure if I can change my get-culture to UK or something and see if that works.
thanks for any info and the help you already gave - appreciated.
pg
I did use the method from the feb 27 ādatepicker formatā forum post by Jacob-evansā¦
it seemed no matter what config we used the -type ādateā is set with a format that will not change (as far as I know - which isnāt far at all ;-)). so I just took the variable $datep and then broke it up into partsā¦not pretty but hopefully this will do the job. itās just the users will question why it shows initially on the form day month year but will be inserted into the db as month day yearā¦
As for the output format, this is hardcoded in the Ud-input-field.jsx React component behind the scenes
As you can see, it is hardcoded to use DD-MM-YYYY and do not make use of system culture or anything else.
didnāt work because $var is a system.datetime object and you specify the output as @itfranck originally suggested. Take my hat off to the solution that was provided and for the reason behind why it is always formatted as dd-mm-yyyy in the ud-input-field.jsx file learn something new everyday as they say.
Oh ! A lot simple to just use the Powershell Get-Date than going .net for the date conversion. I never used that cmdlet to parse an existing date before. Great !