Export (0) Print
Expand All
Expand Minimize

Converting VBScript's Year Function


Windows PowerShell


Definition: Returns a whole number representing the year.

Year

Don’t feel bad: sometimes the Scripting Guys forget what year it is, too. Or at least we used to, until we realized we could use Windows PowerShell to determine the year for us. All we have to is call the Get-Date Cmdlet and then grab the value of the Year property. For example, this command retrieves the current year and stores that value in the variable $a:


$a = (get-date).year

When you run this command and then echo back the value of $a you should get the following (assuming the command was run during the year 2006):


2006

Of course, you can determine the year for any date; all you have to do is ask Get-Date to work with that date instead. For example, this command returns the year for the date 9/15/2005:


$a = (get-date "9/15/2005").year

When you run this command and then echo back the value of $a you should get the following:


2005


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft