-
-
Save aadennis/db241ebab7ee8631d10eee208bf1c1bb to your computer and use it in GitHub Desktop.
Powershell date parts swapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The date formats here are frequently seen in British English locales. | |
This whole piece can be used to test swapping date placeholders, with the PowerShell command that does | |
the swapping on the last line. | |
The command assumes the text has been saved to history.txt in the current folder. | |
The Battle of Hastings took place on 14/10/1066 between Harold and William. The war between the 2 was triggered | |
by Edward the Confessor's death on 12/06/1066. | |
Fast forward to the 20th century, and we say that usually the Second World War is considered to have started on | |
01/09/1939, followed by the Potsdam Declaration - 26/07/1945. | |
And finally some extremes: 01/01/0001 and 09/10/3987. | |
$(Get-Content -Path .\mah.txt) -replace '([0-9]{2})/+([0-9]{2})/+([0-9]{4})','$2-$1-$3' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment