Converting VBScript's Year Function
Definition: Returns a whole number representing the 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):
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: