Chapter 13. Going On a Date with PowerShell
In This Chapter
Getting a date
Performing date calculations
Working with time zones
Whether you're scheduling an automated task, generating time stamp–based log file names, or trying to deal with date-related problems such as the infamous Y2K bug or the change in daylight saving time, dates are an important part of many computing tasks. Windows PowerShell builds on top of the rich Date
and Time
support provided by the .NET Framework and adds a few features such as the capability to use Unix-style formatters to modify how the dates are presented.
In this chapter, you define dates and times and use them in different scenarios such as calculating elapsed time or figuring out daylight savings time. You might not use dates and times as much as you use other data types, but they're very important because they're very relevant to our day-to-day life. Even if you don't need it just now, make a note of this chapter because soon enough you're bound to need it, even if it's something as simple as trying to display the current date and time to screen.
Going On Your First Date
To work with dates and times in Windows PowerShell, you use the Get-Date
Cmdlet. It's the Swiss Army Knife of Windows PowerShell dates and times; you use it to find out the current date and time as well as to create date objects to define any arbitrary date. To find out the current date and time, you run Get-Date
by itself without any parameters, like this:
Get-Date
When you run this ...
Get Windows PowerShell™ 2 For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.