-
Book Overview & Buying
-
Table Of Contents
SQL Server 2014 with Powershell v5 Cookbook
By :
In this recipe, we simply get the system's current timestamp.
This is how we will get the timestamp:
$timestamp = Get-Date -Format "yyyy-MMM-dd-hhmmtt" #display timestamp $timestamp
Here is a sample result:

Often, we find ourselves needing the timestamp to append to different files we create or modify. To get the timestamp in PowerShell, we simply have to use the Get-Date cmdlet, which gives the following default format:

To change the format, we can use the –Format switch, which accepts a format string. In this recipe, we used the yyyy-MMM-dd-hhmmtt format.
There are a number of standard format strings that return preformatted datetimes, or you can also compose your own format string. The common format strings, as documented in MSDN, are as follows:
|
Format pattern |
Description |
|---|---|
|
|
AM/PM designator |
|
|
Seconds with leading zero |
|
|
Minutes... |