Differences
This shows you the differences between the selected revisions of the page.
2016-09-29 | 2016-09-29 | ||
dissolving more options section into the other sections (martin) | is powershell (martin) | ||
Line 47: | Line 47: | ||
For all options of the relative date/time calculation, see the ''[[scripting#timestamp|%TIMESTAMP%]]'' syntax documentation. | For all options of the relative date/time calculation, see the ''[[scripting#timestamp|%TIMESTAMP%]]'' syntax documentation. | ||
+ | |||
+ | ===== In PowerShell ===== | ||
+ | |||
+ | In PowerShell, you can use its built-in timestamp functions. | ||
+ | |||
+ | To format the current timemestamp, use the ''[[https://technet.microsoft.com/en-us/library/hh849887.aspx|Get-Date]]'' cmdlet and its ''-Format'' switch: | ||
+ | |||
+ | <code powershell> | ||
+ | $timestamp = (Get-Date -Format "yyyy-MM-dd") | ||
+ | Write-Host $timestamp | ||
+ | </code> | ||
+ | |||
+ | To calculate relative times, use methods of the ''[[https://msdn.microsoft.com/en-us/library/system.datetime.aspx|DateTime]]'' class, like the ''[[https://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx|AddDays]]''. To format the calculated timestamp, use the ''[[https://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx|ToString]]'' method. | ||
+ | |||
+ | <code powershell> | ||
+ | $yesterday = (Get-Date).AddDays(-1) | ||
+ | $timestamp = $yesterday.ToString("yyyy-MM-dd") | ||
+ | Write-Host $timestamp | ||
+ | </code> |