cancel
Showing results for 
Search instead for 
Did you mean: 

Returning the date at the beginning of a week in the year

Former Member
0 Kudos

In Crystal Reports 2011, I'm trying to return the first day of the week in the date format m/d/yyyy for a specific week of a prior year.  For example, December 2, 2012 is the 49th week of 2012 and begins on a Sunday.  However 365 days prior to December 2, 2012 is a Saturday and still in the 49th week of 2011.  Is there a function in Crystal that will allow for this?  I've been unsuccessful in finding one.  In the end, what I'm trying to do is to determine the sales for the same week of the prior year.   Any help is appreciated!

Accepted Solutions (0)

Answers (3)

Answers (3)

DellSC
Active Contributor
0 Kudos

To get the Monday for any date, try this:

{date} - DayOfWeek({date}, crMonday) + 1

If I call that formula {@Monday} then the formula to get the week of the year is something like this:

DateDiff('ww', Date(Year({@Monday}), {@Monday}, crMonday)

-Dell

Former Member
0 Kudos

Hi Ron,

In order to calculate the week-over-week comparison between given years you would need to write a series of formulas. You can test the approach given in the following thread:

http://www.crystalkeen.com/articles/crystalreports/calculateweeknumber.htm

Note:- Scroll to the bottom of the page to go through the entire article.

Thanks,

Prathamesh

Former Member
0 Kudos

Hi Ron,

you can use following formula to return the date 365 prior to date stored in DB

datediff("d",-365,{<Database date field>};

however this will not consider if previous year was a leap year or not.

If you want we can modify the formula using if else constuucts to consider leap years also.

I hope this would help

Regards,

Shantanu