Listing Date and Time Information
Let’s start with the simplest scenario first. If all you want is the current date and time then simply call Get-Date without any additional parameters:
[crayon-6a9d66d09e482786243388/]
In return, you’ll get back something similar to this:
[crayon-6a9d66d09e488277687189/]
Ah, but suppose you want only the date, not the date and the time? Then just use the -displayhint parameter and specify date:
[crayon-6a9d66d09e48a138816556/]
Or, if you’d prefer just the time:
[crayon-6a9d66d09e48b528869375/]
You can also use Get-Date to create a date-time object for any date/time. For example, this command creates a variable named $A that maps to 12:00 AM on May 1, 2006:
[crayon-6a9d66d09e48d443069101/]
What’s that? You need to map $A to 7:00 AM on May 1, 2015? Why not:
[crayon-6a9d66d09e48e352007526/]
Get-Date also includes a number of methods for doing some handy-dandy date arithmetic:
- AddSeconds
- AddMinutes
- AddHours
- AddDays
- AddMonths
- AddYears
Need to know the date/time 137 minutes from now? This command will show you:
[crayon-6a9d66d09e490558471997/]