ShowAll Questionssorted byDate Posted
aks001

# 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...... :)

GlynA

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

GlynA

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 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