Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date and Time Calculation Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: Date and Time Calculation
     Posted: 13 Dec 2012 at 11:09am

This formula performs a calculation in days and excludes weekends. Some of the calculations come out to zero because the dates are the same. However, I need to know the differences in minutes and seconds when the dates are the same.

//DateDiff ("s",DateTimeValue ({EpisodeTests.DateAuth},{EpisodeTests.TimeAuth}),
//DateTimeValue ({Episodes.ReportDate},{Episodes.ReportTime}))/60/60


Local DateTimeVar d1 := {EpisodeTests.DateAuth};
Local DateTimeVar d2 := {Episodes.ReportDate};
DateDiff ("d", d1, d2) -
     DateDiff ("ww", d1, d2, crSaturday) -
     DateDiff ("ww", d1, d2, crSunday)

In the database, I have the following fields:
EpisodesTests.DateAuth (Date)
EpisodesTests.TimeAuth (Time)
Episodes.ReportDate (Date)
Episodes.ReportTime (Time)
 
I am ok with changing the difference to minutes or seconds vs. days.
IP IP Logged
martbar
Newbie
Newbie


Joined: 04 Apr 2012
Location: United States
Online Status: Offline
Posts: 15
Quote martbar Replybullet Posted: 14 Dec 2012 at 6:09am
can't you do an IF - THEN?
 

IF
date({EpisodeTests.DateAuth})<>date({Episodes.ReportDate})

THEN

....whatever formulas

ELSE

time({EpisodeTests.DateAuth} - time({Episodes.ReportDate})

IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 16 Dec 2012 at 11:35pm
Basically
 
numbervar Daydiff;
numbervar Actualdiff;
Local DateTimeVar d1 := {EpisodeTests.DateAuth};
Local DateTimeVar d2 := {Episodes.ReportDate};
Daydiff := DateDiff ("d", d1, d2) -
     DateDiff ("ww", d1, d2, crSaturday) -
     DateDiff ("ww", d1, d2, crSunday);
if Daydiff = 0 then
Actualdiff := DateDiff ("s", d1, d2) else Actualdiff := Daydiff;
Actualdiff
You wil have to fiddle about to determine whether you have days or seconds, and to convert your seconds to minutes and seconds.
 
I have a similar formula for working days, that also includes public holidays.
IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 17 Dec 2012 at 7:56am
Thank you!
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