Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: how to combine two variables in If else statement Post Reply Post New Topic
Author Message
rupa
Newbie
Newbie


Joined: 06 Jan 2012
Location: United States
Online Status: Offline
Posts: 2
Quote rupa Replybullet Topic: how to combine two variables in If else statement
     Posted: 06 Jan 2012 at 3:56am
Hi,
   I need some help i have end time 7:48 in HH24:MM
start time 6:09  in HH24:MM out put should be 1:39
i was getting Hours1 = 1
Minutes1 = 39 how can i combine two variables in Else statement ?
I tried
 
 
numbervar nummins_end_p1 :=ToNumber( Left(trim({TableName.END}),2 )) * 3600+
ToNumber(right(trim({TableName.END}) , 2)) * 60 ;

numbervar nummins_start_p1 := ToNumber( Left(trim({TableName.START}),2 )) * 3600+
ToNumber(right(trim({TableName.START}) , 2)) * 60 ;

numbervar TotalSeconds :=  ToNumber(nummins_end_p1 - nummins_start_p1 );
 
numbervar Hours := truncate(TotalSeconds / 3600); 
// trim .00 to get hours
numbervar Hours1 := ToNumber(ToText(Hours, 2));

// Subtract the hours portion to get RemainingSeconds 
numbervar RemainingSeconds := TotalSeconds - (Hours  * 3600); 
 
// Divide RemainingSeconds by 60 to get minutes.
// Use truncate to remove the decimal portion. 
numbervar Minutes := truncate(RemainingSeconds/60); 
numbervar Minutes1 := ToNumber(ToText(Minutes, 2));
// Subtract the Hours and Minutes and what is left over is seconds. 
numbervar Seconds := TotalSeconds - (Hours * 3600) - (Minutes * 60); 
 
// Format the hours, minutes, and seconds to hh:mm:ss 
numbervar hoursmin :=ToNumber(totext(Hours,"00")) + ToNumber(totext(Minutes,"00")) ;
 
If  {Tablename.column} = 0 Then

condition
 else  
 ToNumber(Hours1  & ":" & Minutes1);
 
Ex:- 1:39 I need output like this I tested this formula it is not showing any errors 
 ToNumber(Hours1  & ":" & Minutes1);  but when i run the report it is showing "The String is non numeric".
I tried
If  {Tablename.column} = 0 Then
condition
 else  
 Hours1; // it is giving the hours
I tried
If  {Tablename.column} = 0 Then
condition
 else  
  Minutes1; // it is showing minutes
 
When i use this ToNumber(Hours1  & ":" & Minutes1);   then i am getting "the String is non Numeric error Message"
 
Can any one please guide me through this. I really appriciate it
Thanks in advance 
 


Edited by rupa - 06 Jan 2012 at 4:09am
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 06 Jan 2012 at 5:50am
dateadd('n',datediff('n',#06:09:00#,#07:48:00#),#00:00:00#)
 
Replace the following;
 
#06:09:00# with your starttime field
#07:48:00# with your endtime field
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 06 Jan 2012 at 8:39am
why not just:
datediff('n', {table.start}, {table.end})
 
I guess the question is, is rupa looking to get the difference in start and end times?  the dateadd(datediff()) would seem to be just 1 step too much as all you seem to be doing is add the difference to 0, which is the difference.
 
correct me if I'm wrong...best way to learn.
 
 
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 10 Jan 2012 at 1:31am
Originally posted by lockwelle

why not just:
datediff('n', {table.start}, {table.end})
 
I guess the question is, is rupa looking to get the difference in start and end times?  the dateadd(datediff()) would seem to be just 1 step too much as all you seem to be doing is add the difference to 0, which is the difference.
 
correct me if I'm wrong...best way to learn.
 
 
 
I did it this way as datediff('n', {table.start}, {table.end}) would return solely the number of minutes (99) where as rupa asked for a return of 1:39 (hours and minutes) the dateadd does that.
 
Thanks,
Ryan.


Edited by rkrowland - 10 Jan 2012 at 1:33am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 10 Jan 2012 at 5:15am
Sorry, missed that part.
IP IP Logged
rupa
Newbie
Newbie


Joined: 06 Jan 2012
Location: United States
Online Status: Offline
Posts: 2
Quote rupa Replybullet Posted: 31 Jan 2012 at 7:28am
Hi,
   I tried this answer It worked for me
In Oracle sql
 (( ENDTime - STARTTime) * 24)
we will get hours and min. 
Thanks for all your help ....:)
 


Edited by rupa - 31 Jan 2012 at 7:29am
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