More Fun with Dates (and Times)

# COMMENT: More Fun with Dates (and Times)
#  I got this from the Microsoft TechNet Site, but I thought it was too good not to share.

# ===================================
# $a = Get-Date# Accessing Other Date Properties Using Get-Date
$a = Get-Date
"Day: " + $a.Day
"Month: " + $a.Month
"Year: " + $a.Year
"Hour: " + $a.Hour
"Minute: " + $a.Minute
"Second: " + $a.Second$a = (Get-Date).DayFunction ShortDate {
$a = Get-Date
"Date: " + $a.ToShortDateString()
"Time: " + $a.ToShortTimeString()

}

Function DST {
$a = Get-Date
"Daylight Saving Time: " + $a.IsDaylightSavingTime()
"Day of Week: " + $a.DayOfWeek
"Day of Year: " + $a.DayOfYear
}

Function Zulu {
$a = Get-Date
"Universal Time: " + $a.ToUniversalTime()
}
# Simple Date Arithmetic
Function AddDays {
$a = Get-Date
$a.AddDays(90)
}
Function SubDays {
$a = Get-Date
$a.AddDays(-90)
}
# PowerShell Bonus: Getting an Array of Day/Month Names
Function DayNames {
$a = New-Object system.globalization.datetimeformatinfo
$b = $a.DayNames
$b
}

Function MonthNames {
$a = New-Object system.globalization.datetimeformatinfo
$b = $a.MonthNames
$b
}

$Date = (Get-Date -format "MM-dd-yyyy") #<-- Date looks like 03-09-2011. Gr8 for file names
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s