Date and time manipulation
When you are scripting, there are times where you may need to get the date and time of a system. PowerShell offers the get-date cmdlet, which provides the date and time in many different formats of your choice.
To obtain the date object, execute the following command:
$time = get-date $time
The output of this is shown in the following screenshot:

The standard get-date cmdlet, without any triggers, will generate the long date and time format. When you store the date object in a variable, it is important to remember that the data captured from the cmdlet is a snapshot in time. You'll have to call the get-date cmdlet again to get new values for the updated date and time.
The following table displays all of the date time formatting codes:
|
Format code |
Result |
Example |
|---|---|---|
|
MM |
Month in numeric format |
04 |
|
DD |
Day in numeric format |
15 |
|
YYYY |
Year in numeric format |
2014 |
|
HH |
Hour in numeric format (24hrs) |
14 |
|
hh |
Hour in numeric format (12hrs) |
02 |
|
mm |
Minutes in numeric... |