Skip to content

Instantly share code, notes, and snippets.

@ivanionut
Forked from stevewithington/getWeekOfMonth.cfm
Last active August 29, 2015 14:13
Show Gist options
  • Save ivanionut/816b23c6fe1f2844ae65 to your computer and use it in GitHub Desktop.
Save ivanionut/816b23c6fe1f2844ae65 to your computer and use it in GitHub Desktop.
<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