Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Help me about SUM to different timings Post Reply Post New Topic
Author Message
snkkarthi
Newbie
Newbie


Joined: 17 Feb 2009
Location: India
Online Status: Offline
Posts: 4
Quote snkkarthi Replybullet Topic: Help me about SUM to different timings
     Posted: 17 Feb 2009 at 3:10am
Hi,

I need help for to SUM more than two different timings using crystal reports.

for example :

(00:18:39+00:09:39)

This is urgent help me please.. !


IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Feb 2009 at 7:00am

use dateadd in a formula with a shared variable.  don't forget reset/display formula for your new sum.

hope this helps
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: 17 Feb 2009 at 7:57am

Hi

Does your time field have dates in them or just time information,What you can do is convert all the time values i.e.

Hours

Minutes

to seconds for each the time or date time values you need and add them so you will get the output in seconds once done convert the seconds to hh:mm:ss format.....

Cheers

Rahul

 
This is how you do it.....
 
Create formula to convert the time format to seconds
 
local numbervar hours;
local numbervar minutes;
local numbervar seconds;
// Parse out the hours portion of the string and
// multiply by 3600 to convert to seconds
hours := tonumber({table.timefield}[1 to 2])* 3600;
// Parse out the minutes portion of the string and
// multiply by 60 to convert to seconds
minutes := tonumber({table.timefield}[4 to 5]) * 60;
// Parse out the seconds
seconds := tonumber({table.timefield}[7 to 8]);
// Add up all the seconds
hours + minutes + seconds;
Do these for both time fields once done add the output of converted time i.e. seconds
 
Once done convert the Seconds to Time format creating another formula
 
 
local numbervar RemainingSeconds;
local numbervar Hours;
local numbervar Minutes;
local numbervar Seconds;
//divide the @TotalSeconds by 3600 to calculate
// hours. Use truncate to remove the decimal portion.
Hours := truncate({@Totalsecs} / 3600);
// Subtract the hours portion to get RemainingSeconds
RemainingSeconds := {@Totalsecs} - (Hours * 3600);
// Divide RemainingSeconds by 60 to get minutes.
// Use truncate to remove the decimal portion.
Minutes := truncate(RemainingSeconds/60);
// Subtract the Hours and Minutes and what is left
// over is seconds.
Seconds := {@Totalsecs} - (Hours * 3600) - (Minutes * 60);
// Format the hours, minutes, and seconds to hh:mm:ss
totext(Hours,"00") + ":" + totext(Minutes,"00") + ":" + totext(Seconds,"00");
 
 
Cheers
 


Edited by rahulwalawalkar - 17 Feb 2009 at 7:59am
IP IP Logged
snkkarthi
Newbie
Newbie


Joined: 17 Feb 2009
Location: India
Online Status: Offline
Posts: 4
Quote snkkarthi Replybullet Posted: 02 Mar 2009 at 3:25am
Hi rahul,

sorry for late reply..!

i am try this formula but it show me an error..!

The string is non-numeric.
Error in File C:\Docume~1\Admin~1\.........{7asd79dd769d}.rpt
Error in formula <Totalsecs>.
'local numbervar hours;
'
The string is non-numeric.










IP IP Logged
snkkarthi
Newbie
Newbie


Joined: 17 Feb 2009
Location: India
Online Status: Offline
Posts: 4
Quote snkkarthi Replybullet Posted: 02 Mar 2009 at 5:39am
hi lockwelle ,

i am not able to get clearly in your answer, can u explain in detail please.....?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Mar 2009 at 6:18am
my answer assumes you need to sum for a section of a report, ie summing the all the times in the details to be displayed in a group footer.
 
a formula would set the value of your shared variable to 0, one would display it and one would add it.  The adding would be handled by the dateadd function (use help to get its syntax).
 
shared variables are declared by using 'Shared numbervar Varname'.  Rahul used local variables, exactly the same declaration and assignment, just the local is changed to shared.
 
hope this helps
IP IP Logged
snkkarthi
Newbie
Newbie


Joined: 17 Feb 2009
Location: India
Online Status: Offline
Posts: 4
Quote snkkarthi Replybullet Posted: 02 Mar 2009 at 6:32am
shared variables are declared by using 'Shared numbervar Varname'.  Rahul used local variables, exactly the same declaration and assignment, just the local is changed to shared.

if i use this. i am getting same error what i am got before....
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: 03 Mar 2009 at 4:57am
Hi
 
Do you have date in the time filed,you need to extract juts the time part using Time function,see if that helps or mail me your report
 
Cheers
Rahul
IP IP Logged
rajeshnsn
Newbie
Newbie
Avatar

Joined: 18 May 2009
Location: India
Online Status: Offline
Posts: 2
Quote rajeshnsn Replybullet Posted: 18 May 2009 at 11:17pm
For me its a different requirement.
 
I want to take average of difference between to date's .
 
 
i am using datediff() in in formula and using summary i am doing the average.
 
It gives in seconds for example : 5788
 
but i want in DAys: HOURS:Minutes:seconds ...like "0days 01:36:28".
 
Can anyone give idea?
rajesh
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 May 2009 at 6:47am
If it gives the correct value in seconds...I would just create the values that I need from that.
say days are 24*3600. see how many are in your seconds, subtract the intregral number of days from the seconds and move onto hours (3600) then minutes (60) and what ever is left is seconds.
 
then format your numbers to appear as you want...only because I don't believe that there is a built in function that will display as you want.
 
if you have the seconds, you can figure out the rest, and formating isn't that hard.
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