Easy way to get current year
I am looking for a way to get the current year as a number. I have tried to use the following but it doesnt seem to work.
=Date.prototype.getFullYear()
What am i doing wrong?
-
Officiell kommentar
I would use:
=(new Date()).getFullYear()
-
Try the Format Date activity. The Date input is =Date.now(). Choose whatever format you need. You can then create a value from the result. In my case, I use the LL format and to get the current year # I create a value with the expression - =parseInt($date.formatted.substr($date.formatted.length -4)) where “date” is the ID of the Format Date activity.
1 -
Thank you Bill. This worked for me.
0 -
Note that $date.formatted may depend on the user's locale, so Bill's solution will only work if the year is the last part of the formatted value. Ryan's solution will always work.
If you still prefer Format Date, I'd use $date.iso.substring(0,4) . Also, substr() is deprecated, use substring() instead.
1
Du måste logga in om du vill lämna en kommentar.
Kommentarer
4 kommentarer