Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: format minues to hours and minutes Post Reply Post New Topic
Author Message
Despina
Newbie
Newbie


Joined: 30 Mar 2010
Location: Australia
Online Status: Offline
Posts: 31
Quote Despina Replybullet Topic: format minues to hours and minutes
     Posted: 13 Jul 2010 at 5:54pm

Hello

 

I want to convert minutes value into an hours and minutes value using a formula in crystal reports however I am not sure how to do this

 

 

Current value (Minutes)        Expected Value (Converted to Hrs and Minutes)

185                                                      = 3.05

55                                                        =0.55

240                                                      = 4.00

238                                                      = 3.58

2                                                          = 0.02

 

 

Regards,

Despina

IP IP Logged
Emir_W
Senior Member
Senior Member
Avatar

Joined: 25 Apr 2010
Online Status: Offline
Posts: 228
Quote Emir_W Replybullet Posted: 13 Jul 2010 at 7:12pm
create a formula to check hours & minutes.
xhours=
if int({?Minutes}/60)<10 then "0"+totext(int({?Minutes}/60),0)
else totext(int({?Minutes}/60),0)
 
xminutes=
if {?Minutes}-((int({?Minutes}/60))*60)<10 then
    "0"+totext({?Minutes}-((int({?Minutes}/60))*60),0)
else
    totext({?Minutes}-((int({?Minutes}/60))*60),00)
 
 
so it will gives you:
185 --> 03:05
55  --> 00:55
240 --> 04:00
238 --> 03:58
2  --> 00:02
 
 
 
hope it help.
 
 
Emir W
IP IP Logged
n920493
Newbie
Newbie


Joined: 14 Jul 2010
Location: Malaysia
Online Status: Offline
Posts: 1
Quote n920493 Replybullet Posted: 14 Jul 2010 at 3:47am
hi, i was trying to convert min to hour format and
the code above
if ({@convertm}/60<10 )
then "0"+ totext(({@convertm}/60),0)
else totext(({@convertm}/60),0)
 
however it appear with the error message sayining that  a number, or currencry amounth is required here.
IP IP Logged
Emir_W
Senior Member
Senior Member
Avatar

Joined: 25 Apr 2010
Online Status: Offline
Posts: 228
Quote Emir_W Replybullet Posted: 14 Jul 2010 at 9:30am
make sure your formula (@convertm) the result is a number or currency.
 
or you can put the formula detail (@convertm) that you have here.
so we can discuss it.
 
 
Emir W
IP IP Logged
Despina
Newbie
Newbie


Joined: 30 Mar 2010
Location: Australia
Online Status: Offline
Posts: 31
Quote Despina Replybullet Posted: 29 Jul 2010 at 3:22pm

Hi,

 

Thank you for your feedback.  I have been away for a while however I just got back and tried the recommended formula above however when I try to validate it it CR says the remaining test does not appear to be part of the formula (it actually highlights all test)

 

I am new at this and I am not sure what I am doing wrong.  This is what I have put in:

 

xhours=
if int({{Command.WRKD_MINUTES}}/60)<10 then "0"+totext(int({{Command.WRKD_MINUTES}}/60),0)
else totext(int({{Command.WRKD_MINUTES}}/60),0)
 
xminutes=
if {{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60)<10 then
    "0"+totext({{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60),0)
else
    totext({{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60),00)
 
xprintall= {@xhours}+":"+{@xminutes}

 

Appreciate any assistance

 

Regards,
Despina

IP IP Logged
Despina
Newbie
Newbie


Joined: 30 Mar 2010
Location: Australia
Online Status: Offline
Posts: 31
Quote Despina Replybullet Posted: 29 Jul 2010 at 3:25pm

Sorry Amendment to my last update.  This is what I have out in and CR says the following does not appear to be part of the test (Command.WRKD_MINUTES)

 

Regards,
Despina

 

 

 

Global StringVar xhours=

if int({{Command.WRKD_MINUTES}}/60)<10 then "0"+totext(int({{Command.WRKD_MINUTES}}/60),0)

else totext(int({{Command.WRKD_MINUTES}}/60),0)

 

Global StringVar xminutes=

if {{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60)<10 then

    "0"+totext({{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60),0)

else

    totext({{Command.WRKD_MINUTES}}-((int({{Command.WRKD_MINUTES}}/60))*60),00)

 

xprintall= {@xhours}+":"+{@xminutes}

IP IP Logged
Emir_W
Senior Member
Senior Member
Avatar

Joined: 25 Apr 2010
Online Status: Offline
Posts: 228
Quote Emir_W Replybullet Posted: 29 Jul 2010 at 8:25pm
both of you missed tonumber().
 
 
Global StringVar xhours=
if int(tonumber({Command.WRKD_MINUTES})/60)<10 then "0"+totext(int(tonumber({Command.WRKD_MINUTES})/60),0)

else totext(int(tonumber({Command.WRKD_MINUTES})/60),0)

 

Global StringVar xminutes=

if tonumber({Command.WRKD_MINUTES})-((int(tonumber({Command.WRKD_MINUTES})/60))*60)<10 then

    "0"+totext(tonumber({Command.WRKD_MINUTES})-((int(tonumber({Command.WRKD_MINUTES})/60))*60),0)

else

    totext(tonumber({Command.WRKD_MINUTES})-((int(tonumber({Command.WRKD_MINUTES})/60))*60),00)

 
 
 
hope it help.
 


Edited by Emir_W - 29 Jul 2010 at 8:31pm
Emir W
IP IP Logged
Despina
Newbie
Newbie


Joined: 30 Mar 2010
Location: Australia
Online Status: Offline
Posts: 31
Quote Despina Replybullet Posted: 03 Aug 2010 at 4:01pm

Thankyou for the reply.  The result is just giving me a true false value returned.  The field WRKD_MINUTES  is alreaby set up as a number. 

Have i missed a critical point?
 
Regards,
Despina
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 04 Aug 2010 at 4:41am
Unless you are using 'Basic syntax' (and it does not look like it).  'Crystal Syntax' requires the ':=' for assignment statements.  '=' is for comparisons.
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