By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


Year(vDate)

The year function is passed a date and returns the numerical year.

Immediate Window Ctrl G


? year(#03-18-2020#)
2020

? year("jan 1, 2019)
2019

? year(Now())
2021

? year(3/19/2021)
1899

? 3/19/2021
7.812034E-05

? format(1,"yyyy-mm-dd")



Note that to pass a constant date you must enclose it in #.....# (pound or hash). That's because if you use 3/19/2020 VBA thinks you're doing a division.

The reason the last example above is returning 1899 is that dates are really the number of days between Dec. 30, 1899, and today.