Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to separate dates store in the same field Post Reply Post New Topic
Author Message
Ytalo
Newbie
Newbie
Avatar

Joined: 01 Feb 2017
Location: United States
Online Status: Offline
Posts: 5
Quote Ytalo Replybullet Topic: How to separate dates store in the same field
    Posted: 07 Feb 2017 at 3:53am
I am trying to extract two different dates data store in the same field, depending on a different field...

log.date      lot.type
01/01/2016    open
01/03/2016    closed

What I am trying to do is to put the open date in one column and closed date in a different column, so I can get the duration of time between open date and closed date... thanks for any help.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 07 Feb 2017 at 4:32am
There are lots way this is possible. But one way that I like to do it is with shared variables.  It works better if you are grouping by something.  So in the details you would have a formula.  One for the open date and one for the closed date (You could eliminate part of the code if you can guarantee the order of the dates). 

The code for each formula would be similar

shared vardate opendate;
if {lot.type} = 'open' then opendate := {log.date};
// This assumes more than two types
shared vardate closeddate;
if (lot.type} = 'closed' then closeddate := {log.date};

then in the group footer you would have a formula for each variable .

shared opendate;  //This will display the date
Then you will have a formula that will do a date diff (I do not know what kind of duration you want).
IP IP Logged
Ytalo
Newbie
Newbie
Avatar

Joined: 01 Feb 2017
Location: United States
Online Status: Offline
Posts: 5
Quote Ytalo Replybullet Posted: 07 Feb 2017 at 4:50am
The date field has a time too, and I am trying to get the duration in HH:MM:SS, from open to close

Thank you for your help, I am going to try it now.
IP IP Logged
Ytalo
Newbie
Newbie
Avatar

Joined: 01 Feb 2017
Location: United States
Online Status: Offline
Posts: 5
Quote Ytalo Replybullet Posted: 07 Feb 2017 at 5:06am
It didn't work... I am not proficient in writing formulas can you explain in detail... and again thank you for your help and patience.   
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 07 Feb 2017 at 7:00am
Opps!!  I wrote the variable declarations wrong.  They should be datevar not vardate.

First you did not explain if you were grouping.  It works pretty well if you are grouping.

The code above (with the if statements) would go in the details section. Then in the group footer you would have a formula similar to below.

shared datevar opendate;
shared datevar closeddate;
diff=datediff( "s",opendate, closeddate);
// convert to string as 00:00:00  will find code later
IP IP Logged
Ytalo
Newbie
Newbie
Avatar

Joined: 01 Feb 2017
Location: United States
Online Status: Offline
Posts: 5
Quote Ytalo Replybullet Posted: 07 Feb 2017 at 7:22am
I get an error message after diff=datediff......
"the remaining text does not appear to be part of the formula"
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.