Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stevewithington/922c722707d0a4ac96ae to your computer and use it in GitHub Desktop.
Save stevewithington/922c722707d0a4ac96ae to your computer and use it in GitHub Desktop.
ColdFusion / CFML : Get Week of Month (1-5)
<cfscript>
public any function getWeekOfMonth(date d='#Now()#', numeric minDaysInFirstWeek=1) {
var cal = CreateObject('java', 'java.util.GregorianCalendar').init(
JavaCast('int', Year(arguments.d))
, JavaCast('int', Month(arguments.d)-1)
, JavaCast('int', Day(arguments.d))
, JavaCast('int', Hour(arguments.d))
, JavaCast('int', Minute(arguments.d))
, JavaCast('int', Second(arguments.d))
);
cal.setMinimalDaysInFirstWeek(arguments.minDaysInFirstWeek);
return cal.get(cal.WEEK_OF_MONTH);
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment