Tips and Tricks
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Tips and Tricks
Message Icon Topic: First Monday of the month Formula? Post Reply Post New Topic
Author Message
acertik
Newbie
Newbie
Avatar

Joined: 16 Jan 2012
Online Status: Offline
Posts: 12
Quote acertik Replybullet Topic: First Monday of the month Formula?
    Posted: 24 Mar 2012 at 12:05pm
Does anyone know what formula I might be able to use to return a date for the first Monday of the month?
 
I am trying to come up with a way that a report will tell me specifically when Labor Day is every year (U.S.), which is the first Monday in September.
 
Thank you in advance,
 
Alexander Certik
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 29 Mar 2012 at 2:44am
dateadd("d",8-dayofweek(date(2011,08,31),crmonday),date(2011,08,31))
 
You could replace the 2011 with something like year({table.datefield}) to find what date labor day was in relation to a transaction date.
 
Regards,
Ryan.


Edited by rkrowland - 29 Mar 2012 at 5:36am
IP IP Logged
acertik
Newbie
Newbie
Avatar

Joined: 16 Jan 2012
Online Status: Offline
Posts: 12
Quote acertik Replybullet Posted: 29 Mar 2012 at 12:19pm
Thanks Ryan.
 
If you have time, would you be able to explain how this formula works? Only if it's convenient.
 
Thank you,
 
Alexander Certik
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 29 Mar 2012 at 11:10pm

The dateadd function is adding a calculated number (8-dayofweek(date(2011,08,31),crmonday)) of days ("d") to a specified date (date(2011,08,31)).

Our starting date is always the last day of August as the first Monday in September has to fall within 7 days of this date.
 
So basically we've got add x days to 31/08/YYYY.
 
x = 8-dayofweek(date(2011,08,31),crmonday)
 
This dayofweek part of the formula calculates what day of the week the last day in August was if we say a week begins on monday (crmonday). IE if the 31/08/YYYY is a monday it will return 1, it's was a tuesday it will return 2 etc.
 
We'll go with our example and say the 31st of August was a Tuesday.
 
This is what's returned; dateadd("d",8-2,31-08-YYYY)
 
Which basically means the first Monday was the 6th of September.
 
Regards,
Ryan.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.035 seconds.