Skip to content

Instantly share code, notes, and snippets.

@beancurd1
Created December 31, 2015 11:48
Show Gist options
  • Save beancurd1/57060774f02c3b3083e9 to your computer and use it in GitHub Desktop.
Save beancurd1/57060774f02c3b3083e9 to your computer and use it in GitHub Desktop.
Powershell: Date Format, Conversion, Calculation
### [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 $StartDateEnd $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