Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date for each friday of the month (Urgent) Post Reply Post New Topic
Author Message
Elisha83
Groupie
Groupie


Joined: 19 Feb 2008
Location: Malaysia
Online Status: Offline
Posts: 62
Quote Elisha83 Replybullet Topic: Date for each friday of the month (Urgent)
     Posted: 20 Jun 2010 at 7:48pm
Hi there,
 
I need help in formula of getting each friday of the month and the best way I should do in order to generate the report output faster. Below are roughly the output of report that I wish to create.
 
 
Example :
 
No.  Tenant       Receipt(07/05/10)  Receipt(14/05/10) Receipt(21/05/10) ...
1         A                                                 1200
2         B                   2000
3         C                                                                              1000
 
 
Question:
1) Should I create subreport for first friday, another subreport for 2nd friday, follow by the subsequence friday?
2) What formula I should write in order to get the date for each friday of the month?
 
 
Please advice as I urgently need help on this.
 
 
 
Thanks in advance..
 
Eli Smile
3Lish@
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 21 Jun 2010 at 7:52am

Hi,

I am not sure what table structure you have to get the data.

Hope you have  table which list the Dates for specific Month...


if you already have the DataTable Which List the Dates the just Find the DateName  for all the Dates in the Month

Crystal Code
weekdayname(dayofweek({Table.FieldName})) this will list the weekday like Monday Tuesday and so on
 
so just filter your report on startdate enddate for that month where weekdayname is Friday.
 
sql code

DATENAME(DW,DateField))

*Then in your report just select the DateName where it is Friday.

*************************************************
If you don't have DatesTable you can build one using the SQL Code Below to build it from Scratch with the same ID as ID in your DataTable and link them both.


I have used Identity for the sample
 
CREATE TABLE [dbo].[DateTab](

[ID] [int] IDENTITY(1,1) NOT NULL,

[StartDate] [datetime] NULL,

[DayName] [nvarchar](50) NULL

) ON [PRIMARY]

GO

Declare
@startdate datetime,
@enddate  datetime
 
set @startdate =DATEADD(DAY,1-DATEPART(DAY,GETDATE()),GETDATE()) --StartDate
set @enddate= DATEADD(DD,-DAY(DATEADD(M,1,@startdate)),DATEADD     --EndDate
(M,1,@startdate))

While @startdate <= @enddate
begin
insert into dbo.DateTab(StartDate,DayName) values(DATEADD(DD,@cnt,@startdate),DATENAME(DW,@startdate))
set @startdate =@startdate + 1

end

Hope that helps

Cheers
Rahul
 



Edited by rahulwalawalkar - 21 Jun 2010 at 7:57am
IP IP Logged
DigYerOwnHole
Newbie
Newbie
Avatar

Joined: 07 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 1
Quote DigYerOwnHole Replybullet Posted: 22 Jun 2010 at 1:15am
Does this work:

//Get The 1st Day of the current month
NumberVar nToday := DayOfWeek(Date(Year(Today()), Month(Today()), 01));

//First Friday is:
Date(Year(Today()), Month(Today()), 7 - nToday)


That's the first Friday's date, subsequent Fridays will be +7 days therein
IP IP Logged
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