Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Comparing dates in formula Post Reply Post New Topic
Author Message
tlmoses
Newbie
Newbie


Joined: 17 Jul 2007
Online Status: Offline
Posts: 3
Quote tlmoses Replybullet Topic: Comparing dates in formula
    Posted: 17 Jul 2007 at 10:33am
I would like to be able to compare dates to know which was later. 
I have Date1 and Date2, where sometimes Date 2 is not set.
 
If I do this:
 
if Date2>Date1 then
   Date2                            
else
   Date1
 
I always get Date 2, even when there isn' t a date set in the field.  I would like to get Date2 if it is later and if it is not set, use Date1.  These values are declared as dates in the table that I pull them from .
 
How do I compare them?
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 17 Jul 2007 at 2:13pm

You might try this.

Test Date2 to make sure it is a vaild date by using the ISDate function. Your formula would look something like this.

------------------------------

datevar x; 
 
IF IsDate({Date2}) AND Date2>Date1 THEN
  x:= Date2                            
else
   x := Date1;
x;
-----------------------------------

Hope this helps
 
 
John W.
IP IP Logged
tlmoses
Newbie
Newbie


Joined: 17 Jul 2007
Online Status: Offline
Posts: 3
Quote tlmoses Replybullet Posted: 18 Jul 2007 at 5:14am
Thanks for the suggestion, but I have tried "isdate" and I get a Crystal error that it is expecting a string.
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 18 Jul 2007 at 7:51am
I tried this much of the formula with the changes and this much works.
--------------------
stringvar x;
 
IF IsDate(Cstr({Orders.Ship Date}))  THEN
  x:= (Cstr({Orders.Ship Date}))                   
else
   x := "Nodate";
x;
----------------------
You will need to deal with the 'AND Date2>Date1' issue, I did not have two dates in my sample database to quickly compare.  You could also use the totext function of CR instead of the CStr
 
Hope this helps
 
Regards,
 
John W.
IP IP Logged
tlmoses
Newbie
Newbie


Joined: 17 Jul 2007
Online Status: Offline
Posts: 3
Quote tlmoses Replybullet Posted: 18 Jul 2007 at 9:57am
Thanks - I solved my problem with the last suggestion!
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.