Monthly Archive

Categories

W2KSG: Date Parts

I am going to skip a bit of the guide as the input and error handling are quite different between VBScript and PowerShell.  We will see both of those concepts later.  For now we will jump forward to looking at dates

Script Center Home > Microsoft Windows 2000 Scripting Guide > Scripting Concepts and Technologies for System Administration > VBScript Primer > VBScript Reference > Working with Dates and Times  Retrieving Specific Portions of a Date and Time Value

$now = Get-Date
"Now: $now"
"Year: $($now.Year)"
"Month: $($now.Month)"
"DayOfYear: $($now.DayOfYear)"
"Day: $($now.Day)"
"DayOfWeek: $($now.DayOfWeek)"
"Hour: $($now.Hour)"
"Minute: $($now.Minute)"
"Second: $($now.Second)"

Use get-date to retrieve the date and then pick off the parts as shown. .NET doesn't provide for Quarter or Week of Year so we can't do those. Notice the $($now.xxx) structure.  This forces the expression to be evaluated and then substituted.

 

Share this post :

Technorati Tags: PowerShell

Leave a Reply