Created
December 31, 2015 11:48
-
-
Save beancurd1/57060774f02c3b3083e9 to your computer and use it in GitHub Desktop.
Powershell: Date Format, Conversion, Calculation
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
### [datetime] ALWAYS assumes MDY format irrespective of your culture when the following format is being converted | |
### therefore, it requires to use ParseExact in order correct this | |
[datetime]::ParseExact('9/11/2015','d/MM/yyyy', $null).ToString('dd MMM yyyy') | |
([datetime]'9 Dec 2015').ToString('dd MMMM yyyy') | |
Get-Date -Format 'dd MMM yyyy' | |
### Different ways of calculating TimeSpan | |
$StartDate = (GET-DATE) | |
$EndDate = [datetime]::ParseExact('22/12/2015','d/MM/yyyy', $null) | |
NEW-TIMESPAN –Start $StartDate –End $EndDate | |
$EndDate - $StartDate | |
($EndDate - $StartDate).Days | |
(Get-Date).AddDays(($EndDate - $StartDate).Days).ToString('dd MMM yyyy') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment