Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Ugh, Adding Days Post Reply Post New Topic
Author Message
ja_cote
Newbie
Newbie


Joined: 09 Jul 2008
Online Status: Offline
Posts: 12
Quote ja_cote Replybullet Topic: Ugh, Adding Days
     Posted: 04 Jun 2009 at 6:20am
So, first, I am sure somewhere embedded in this forum there are countless examples of this formula.  My search did not yield a solution I was comfortable with.  So, here's my problem.
 
I need a formula that will add days to a date based on a terms code.
 
So, here's the non-formula, layman's "formula"
 
If  {termscode} = "01" then {receiptdate} + 30
 
In even more simple terms, I want to add a specific number of days to a date field in the record. 
 
I use MAS200, if there are any of you in here...poor souls.
 
Thanks for the assist.
 
Jeff
Jeff in New Hampshire
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Jun 2009 at 6:26am
If  {termscode} = "01" then DATEADD(d,30,{receiptdate})
 
you may need to add quotes around the d...
DATEADD("d",30,{receiptdate})
 
HTH
IP IP Logged
ja_cote
Newbie
Newbie


Joined: 09 Jul 2008
Online Status: Offline
Posts: 12
Quote ja_cote Replybullet Posted: 04 Jun 2009 at 6:40am
Hmmm....Thanks for the formula.  However, this still produced an error.
 
if {POP_RecptHistoryHeader.TermsCode} = ["00"] then DATEADD(d,30,{POP_RecptHistoryHeader.ReceiptDate})
 
as did
 
if {POP_RecptHistoryHeader.TermsCode} = ["00"] then DATEADD("d",30,{POP_RecptHistoryHeader.ReceiptDate})
 
Maybe I'm being dopey and not understanding what "d" is.
 
 
 
 


Edited by ja_cote - 04 Jun 2009 at 6:40am
Jeff in New Hampshire
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Jun 2009 at 6:48am
look at help.  d just stands for Day, so add 30 days, you can also add minutes, seconds, years, etc.
 
My turn to be dopey...I have never seen [] around a value in crystal before.  I associate [] with arrays, and the index of the array shouldn't be a string...but I don't use arrays.
 
I would have thought it would be something like:
if {POP_RecptHistoryHeader.TermsCode} = "00" then DATEADD("d",30,{POP_RecptHistoryHeader.ReceiptDate})
IP IP Logged
ja_cote
Newbie
Newbie


Joined: 09 Jul 2008
Online Status: Offline
Posts: 12
Quote ja_cote Replybullet Posted: 04 Jun 2009 at 7:00am
Well, I did try that method, to no avail.  Here's a more complete formula so you can see the bigger picture.  Sometimes the devil is elsewhere in the details!
 
if {POP_RecptHistoryHeader.TermsCode} = ["00"] then "No Terms"
 
else if {POP_RecptHistoryHeader.TermsCode} = "01" then DATEADD("d",30,{POP_RecptHistoryHeader.ReceiptDate})
 
else "Other"
Jeff in New Hampshire
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: 04 Jun 2009 at 7:29am
HI
 
edit the formula and add totext function to convert the datetime or date value to text because
 
IF expression is an expression and so must always return a value of a single type. [crystal help]
 
 
if {POP_RecptHistoryHeader.TermsCode} = ["00"] then "No Terms"
 
else if {POP_RecptHistoryHeader.TermsCode} = "01" then
totext(DATEADD("d",30,{POP_RecptHistoryHeader.ReceiptDate}))
 
else "Other"
 
 
cheers
Rahul


Edited by rahulwalawalkar - 04 Jun 2009 at 7:32am
IP IP Logged
ja_cote
Newbie
Newbie


Joined: 09 Jul 2008
Online Status: Offline
Posts: 12
Quote ja_cote Replybullet Posted: 04 Jun 2009 at 8:24am

Rahul and all...Thanks for the assist.  Good stuff.

Jeff in New Hampshire
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