Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: count weeks between 2 conditions Post Reply Post New Topic
Author Message
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Topic: count weeks between 2 conditions
     Posted: 23 Aug 2010 at 5:58am
Hi All

Hope i'm at the right place....

Firstly i am brand new to this so please be patient if i sound a little stupid.

Could any one help how i can calculate the number of weeks in each record using the start date found in lotus named CON.OnSiteStart to the current system date.

I guess a simple fomula could be produced but just dont know where to start. Anyone step by step help would be greatly appreciated...

Ian

Confused
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Aug 2010 at 6:18am
depends on how you define a week exxactly but in general you can use datediff with either w or ww as the interval
datediff('?',{CON.OnSiteStart},currentdate())
 
here is the defintiions of w and ww from HELP
 

Use DateDiff with the "w" parameter to calculate the number of weeks between two dates. For example, if startDateTime is on a Tuesday, DateDiff counts the number of Tuesdays between startDateTime and endDateTime not including the initial Tuesday of startDateTime. Note however that it counts endDateTime if endDateTime is on a Tuesday.

DateDiff ("w", #10/19/1999#, #10/25/1999#)

Returns 0.

DateDiff ("w", #10/19/1999#, #10/26/1999#)

Returns 1.

Use DateDiff with the "ww" parameter to calculate the number of firstDayOfWeek's occurring between two dates. For the DateDiff function, the "ww" parameter is the only one that makes use of the firstDayOfWeek argument. It is ignored for all the other interval type parameters. For example, if firstDayOfWeek is crWednesday, it counts the number of Wednesday's between startDateTime and endDateTime. It does not count startDateTime even if startDateTime falls on a Wednesday, but it does count endDateTime if endDateTime falls on a Wednesday. For the examples, note that October 6, 13, 20 and 27 all fall on a Wednesday in 1999.

DateDiff ("ww", #10/5/1999#, #10/29/1999#, crWednesday)

Returns 4.

DateDiff ("ww", #10/6/1999#, #10/29/1999#, crWednesday)

Returns 3.

DateDiff ("ww", #10/5/1999#, #10/27/1999#, crWednesday)

Returns 4.

IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 23 Aug 2010 at 6:46am
How do i insert that into the group footer to show the number of weeks? between them dates.
i'm defining the weeks every 7 days as 1 week from on site date
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Aug 2010 at 6:51am
i cannot see images on this site.
 
If you want to count every 7 days then create a formula field using the 'w' interval as:
datediff('w',{CON.OnSiteStart},currentdate())
 
what is your row level data?
what is your grouping?
how do you want to count the results?
IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 23 Aug 2010 at 7:03am
I am very very new to crystal as you can prob see already. On the info you have given me i will get my head in a book tonight to try and clarify my objective. i will try to explain more tomorrow.

Many thanks for your patience.

Ian
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Aug 2010 at 7:11am

no problem.

for clarity, a common mistake I see people make early on is that they put 'conversion' formulas (like what you wanted) in the select expert instead of a new formula field.
The select expert is only used for limiting data rows.
You want to create a new formula field.
right click on the formula fields in the field explorer and select new
name it whatever (e.g. 'WeekAmount')
put in the formula i gave you
datediff('w',{CON.OnSiteStart},currentdate())
save it.
place the new formula field on the detail section to see the resulting number for each row.
IP IP Logged
ianwells
Newbie
Newbie


Joined: 23 Aug 2010
Online Status: Offline
Posts: 11
Quote ianwells Replybullet Posted: 23 Aug 2010 at 8:59pm
Morning DBlank

Firstly thankyou very much for your help and direction.

I got my head in a book last night and realised the very thing i now read in your reply. i managed to get the result i was looking for from your guidence and used a slightly different formula, i know not the reason why it works looking at yours but hey ho, here is what i used without a set of brackets

datediff ("w", {CON.OnSiteStart},currentdate)

Thank you again for your help.

Headscratching times ahead i feel ha

cheers Ian
Clap
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Aug 2010 at 3:56am
oops.
I gave you a hybrid of crystal (currentdate) and sql (getdate()) and made up my own version of currentdate().
 
Glad you got it sorted out  Thumbs%20Up
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