You need to sign in to do that
Don't have an account?
jason.wan
Calculate week of the month in Apex Classes
Anyone know of a way to get the Week of the Month (number 1 to 5 depending on month/calendar) in Apex Classes?
If there is custom code that someone has built, please let me know. THANKS.
I only found Day of Year for the Salesforce datetime methods.
example: Day of Year
Datetime myDate = datetime.newInstance(2008, 2, 5, 8, 30, 12);
system.assertEquals(myDate.dayOfYear(), 36);
Hi,
This was one of the utility code we had few months before. Here we assume that first week of the month is any number of days between First day in the month and the weekend (i.e. Saturday) and the last week is any day between last day and last weekend.
Hope this code helps.
All Answers
This will calculate an integer value for WeekOfMonth. The trick for me was that you have to cast the Integer for Day into a Double to make sure the Math.ceil function works properly.
Have fun!
Jeremy
Hi,
This was one of the utility code we had few months before. Here we assume that first week of the month is any number of days between First day in the month and the weekend (i.e. Saturday) and the last week is any day between last day and last weekend.
Hope this code helps.
Look at this: Salesforce uses SimpleDateFormat of JAVA (https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html)