0

I have a requirement to create a record on weekly basis after checking if record is not created for the previous week. how to get the week number for each month and if i am in week 2 of month than how to check if manually record is created for week 1? If not than how to create a record for week1 via batch class? Do we have any function to get the week like we have for month? If yes than how do we get the output from apex in format(i.e. week1, week2, week3 and so on ) for each month.

Integer month = Date.today().month();
3

If you need week-of-month, you can get it from date formatting:

Datetime x = Datetime.now(); //2020-01-16 13:49:19
system.debug(x.format('W')); // 3

You can also get week-of-year, just replace W with w:

Datetime x = Datetime.now().addMonths(1); //2020-02-16 13:49:19
system.debug(x.format('w')); // 8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.