function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
aks001aks001 

calculate week from the date

Hi,

 

I want to calculate the week of day from the end date ,  that it's in ..... like my date is 1/1/2014 to 8/1/2014 and 8/1/2014 to 15/1/2014 ... and the result would be like... 1 , 2, 3 and so on....

 

if anyone has the solution then plz let me know.... thanks in advance...... :)

Best Answer chosen by Admin (Salesforce Developers) 
GlynAGlynA

Try this:

 

public static Integer getWeek( Date theDate )
{
    return (theDate.dayOfYear() - 1) / 7 + 1;
}

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

All Answers

GlynAGlynA

Try this:

 

public static Integer getWeek( Date theDate )
{
    return (theDate.dayOfYear() - 1) / 7 + 1;
}

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

This was selected as the best answer
Sagarika RoutSagarika Rout

date startDate = date.newInstance(2008, 1, 1);
date dueDate = date.newInstance(2008, 1, 30);
integer numberDaysDue = startDate.daysBetween(dueDate);
integer numberOfWeek = numberDaysDue/7;

 

 

Regards

Sagarika Rout

SFDC Developer