Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date format? Post Reply Post New Topic
Author Message
Robotacha
Groupie
Groupie
Avatar

Joined: 11 Nov 2009
Location: United Kingdom
Online Status: Offline
Posts: 97
Quote Robotacha Replybullet Topic: Date format?
     Posted: 17 Nov 2011 at 5:12am
Hello,
 
Am I just being really silly here?
 
I am trying to write this formula:

IF currentdate = 17/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE})) ELSE
IF currentdate = 18/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/2 ELSE
IF currentdate = 19/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/3 ELSE
IF currentdate = 20/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/4 ELSE
IF currentdate = 21/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/5 ELSE
IF currentdate = 22/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/6 ELSE
IF currentdate = 23/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/7 ELSE
IF currentdate = 24/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/8 ELSE
IF currentdate = 25/11/2011 THEN (Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/9 ELSE
(Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/9
 
 
but it is telling me  "A date is required here" where I have typed 17/11/2011
 
Is this just incorrect formatting? how can I resolve this?

 
Thanks.
Regards,

Michael Jones
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Nov 2011 at 5:25am

date(yyyy,mm,dd)

if you want you can also simplify this as :
 
(Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))
/ (if datediff('d',date(2011,11,16),currentdate)>8 then 9 else
datediff('d',date(2011,11,16),currentdate)


Edited by DBlank - 17 Nov 2011 at 5:40am
IP IP Logged
Robotacha
Groupie
Groupie
Avatar

Joined: 11 Nov 2009
Location: United Kingdom
Online Status: Offline
Posts: 97
Quote Robotacha Replybullet Posted: 17 Nov 2011 at 5:30am
many thanks :D
Regards,

Michael Jones
IP IP Logged
Robotacha
Groupie
Groupie
Avatar

Joined: 11 Nov 2009
Location: United Kingdom
Online Status: Offline
Posts: 97
Quote Robotacha Replybullet Posted: 17 Nov 2011 at 6:25am
Just a quick one,

could you explain to me in a simple form how that formula works?

I understand that its the SUM divided by 9 if the datadiff bit is greater than 8,

but how does the last bit of the formula work?
 
what does the 'd' represent? and where does the 16th November come into the equation?
 
much appreciated.
Regards,

Michael Jones
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Nov 2011 at 6:33am
datediff('d',date(2011,11,16),currentdate)
gives you the number of days between today and nov 16th (the 'd' is telling the datediff function to count days).
 
I used nov 16th because I that gave me the same as your If-then division days.
I could have also used
datediff('d',date(2011,11,17),currentdate) +1 which is closer to the way you wrote your if-then statements but not as elegant.
Does that help?
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Nov 2011 at 6:37am
also not ethat techincally I am using
(Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))/1
is the same result as your
(Sum ({@SPECIALS WEEK}, {TRNSTK.STCODE}))
 
my  /1 is derived from the datediff of nov16 and nov 17.
Hence the use of the 16th for the calculations.
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