Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format date with ToString in powershell

$var1 = '06/10/2015 2:00 AM'
$var2 = ([DateTime]($var1)).addMinutes(15).ToString('mm/dd/yyyy hh:mm')
$var2

Current output - 15/10/2015 02:15

but I want - 06/10/2015 02:15

like image 547
mashrur Avatar asked Jan 23 '26 22:01

mashrur


1 Answers

Use 'MM/dd/yyyy hh:mm'. Note the uppercase 'M' for months. Lowercase 'm' is for minutes. These are the .NET custom time format strings documented here.

like image 164
Mike Zboray Avatar answered Jan 26 '26 17:01

Mike Zboray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!