Learn about Windows PowerShell
Summary: Learn how to display only the current year.
How can I use Windows PowerShell to display only the current year?
get-date -Format yyyy
get-date –format yy
get-date –f yyyy
(Get-Date).year
Get-Date -UFormat %Y
Get-Date -UFormat %
"Double, double toil and trouble; Fire burn, and caldron bubble"
It's witchcraft...
More magic from everybodies favorite mad scientist.
@jrv: Magic Ed Wilson @ work ...
The wizard of South Carolina :-)
As Teresa told me, "Date and time voodoo" is one of his hobbies
besides diving, wood working and (underwater) photography
Klaus.
Hi
for fun:
PS> ( date ).ToString('yyyy')
PS> [datetime]::Today.Year
PS> (Get-WmiObject Win32_LocalTime).Year
PS>
@Walid - I'll see you and raise you one:
(date).Year
@JRV hehehe
@K_Schulte thanks ...
@Walid Toumi these are great ... thanks for sharing.
@JRV cool. Thanks.
@JRV @Walid Toumi can you explain WHY Date works? It is not a cmdlets, nor it is a function or an alias!
@IamMred
all cmdlet with verb "get" works
childitem
item
service
only get-process and get-command don't work
because proccess is a special keyword "help keyword"
and command is old shell win command.com
sorry for my english
@Walid - good explanation and your english is fine.
I learned somthing here today. Thank you Walid and Ed.
What you have pointed out is this:
PS>function get-year{date -uf %Y}
PS>year
2012
And remember that these might give a different result to
[DateTime]::UtuNow.Year
@all one of the great things about PowerShell is that is simplifies working with dates. In other languages I have used, datetime manipulation was always a major pain. I still remember old databases that had one column for month, another column for day, and another column for year. UGH!!!