Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: date formula Post Reply Post New Topic
Author Message
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Topic: date formula
    Posted: 02 Jul 2009 at 4:48am
Hey All,
 
I'm working on a CR that has in 1 record 4 date fields.
now i need to create a formula (newthings) that does the following:
 
if 2 out of the 4 date fields have a date that is closer to currentdate then currentdate-14 the formule should get value1 else 0
 
i know i could do this in the record secelction also but i already have a lot of stuff in there. So i would like to make this check seperated so i can use a AND newthings = 0 to filter out all the rows where 2 dates are close to current dates.
 
hope this makes sence.
 
Adam
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 02 Jul 2009 at 6:29am
local numbervar iCount := 0;
if datediff(d,{table.field1},CurrentDate)<14 then iCount:=iCount + 1
if datediff(d,{table.field2},CurrentDate)<14 then iCount:=iCount + 1
if datediff(d,{table.field3},CurrentDate)<14 then iCount:=iCount + 1
if datediff(d,{table.field4},CurrentDate)<14 then iCount:=iCount + 1
if iCount >2 then 1 else 0
 
I might have datadiff backward, so you could either change it to > -14 or reverse the table and currentDate.
HTH
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 02 Jul 2009 at 6:37am
Hey Lockwelle,
 
I made somthing simular now
 
shared numbervar tel;
tel := 0;
IF {ArtikelsLinked.TD} > currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.COP} > currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.IM} > currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.BAS} > currentdate - 14 THEN tel := tel + 1;
 
but strange thing (or not so strange maybe) is that i can't get my tel field correct
what i mean is that if he will only count the COP field if the TD field already did a +1
so for example if both TD and COP are higher as currentdate -14 and IM and BAS are lower they will not be counted?
 
I'll adjust my formula with what you just wrote now and give feedback on that in a couple of min.
 
still curious what's wrong with my formula
 
Greetz and tnx
 
Adam
 
ps: what is the datediff(d, for ?


Edited by AdamField - 02 Jul 2009 at 6:40am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Jul 2009 at 6:55am
datediff is the difference between 2 dates and the d indicates that you want that difference in days rather than month, years, etc.  (although it needs quotes around it)
Datediff("d",date1,date2)
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 02 Jul 2009 at 7:05am

I would look at what the value of currentdate-14 is and TD, etc.  If TD is a date time, then it wouldn't work.  Say today is 7/15, 14 days back would be 7/1.  If TD is 7/1 @ 12:00pm, then 7/15/09 00:00 - 7/1/09 9:00 = 13.5 days.  By using datediff, it looks at anything on the 7/1 as being 7/1, so you would get the expected answer of 14, not 13.xxx

HTH
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 02 Jul 2009 at 7:15am
hey,
 
the time is not important just the date doesn't matter if it was 12 am or 3 pm
 
what i have now with current formula
 
shared numbervar tel := 0;
IF {ArtikelsLinked.TD} < currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.COP} < currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.IM} < currentdate - 14 THEN tel := tel + 1;
IF {ArtikelsLinked.BAS} < currentdate - 14 THEN tel := tel + 1;
 
if for example we say that currentdate is 7/2  so -14 it's 18/6
 
TD    COP      IM     BAS    tel
null    26/2     4/2    null   0   it should be 2 but gives 0 becouse TD is null
25/6  22/4     null   8/5    1  it should be 2 but again  1 becouse of im is checked before bas
9/4  null        6/4     null   1  in stead of 2
 
the times when a date is not there he stops counting and he doesn't do the other formula's any more
i would like to get the formula to do the test for every field what ever the result was from the previous line
 
do i need to split it up in 4 formula's or is there a way to do it in 1 formula ?
 
tnx for the responces already
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 02 Jul 2009 at 7:21am
shared numbervar tel := 0;
IF NOT ISNULL({ArtikelsLinked.TD}) then
 IF {ArtikelsLinked.TD} < currentdate - 14 THEN tel := tel + 1;
IF NOT ISNULL({ArtikelsLinked.COP}) then
 IF {ArtikelsLinked.COP} < currentdate - 14 THEN tel := tel + 1;
IF NOT ISNULL({ArtikelsLinked.TDIMthen
 IF {ArtikelsLinked.IM} < currentdate - 14 THEN tel := tel + 1;
IF NOT ISNULL({ArtikelsLinked.BAS}) then
 IF {ArtikelsLinked.BAS} < currentdate - 14 THEN tel := tel + 1;
 
don't know why, it should continue, but sometimes Crystal is funny.  Give this a try, it should skip the 'bad' values
 
IP IP Logged
AdamField
Groupie
Groupie


Joined: 04 Jun 2009
Online Status: Offline
Posts: 88
Quote AdamField Replybullet Posted: 02 Jul 2009 at 7:25am
Hey Lockwelle,
 
 
Works like a charm, you saved the day :)
 
Tnx
 
Adam
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.031 seconds.