Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

get current year

New Here ,
Oct 22, 2007 Oct 22, 2007
Anyone created a function to get the current year? Here's what I've got so far and it appears to work:
function getCurrentYear() {
var datetime = now();
var month = year(datetime);
return Year(datetime);
}
Is there a better way to code such a function in cfml?
10.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 22, 2007 Oct 22, 2007
I actually wouldn't bother writing a user-defined function for it. #year(now())# is a perfectly reasonable way to reference the current year.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 29, 2017 Dec 29, 2017
LATEST

yes the best way is to use dateformat function. this function takes two arguments the first the date it self, and the second is the date format. in your case for example we can use that function such:

<cfset month = #dateformat(now(), 'mm')#>the output will be 12 for decemeber

this will get you the numeric portion of the month; you can also get fancy with it and get the letters by adding another m such as:

<cfset month = #dateformat(now(), 'mmm')#>the output will be Dec for december.

also coldfusion is rich with other datetime functions that can make life super easy i hope that helped

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources