Crystal Reports : Convert number var to HH:MM in crystal reports


Open the formula field editor in the report, right click on the report custom functions and click on New




The editor window will be opened. Paste the below code in the editor overwriting the text in it.


Function (numbervar Mins);
(
     stringvar tmp := totext((Mins/60 - (truncate(Mins/60))) * 60 ,0);

     select len(totext(truncate(Mins/60),0)) 
     case 1:
               '0' +  totext(truncate(Mins/60),0) + ':' + select len(tmp)
     case 1:
               '0' + tmp
     default:
               tmp
     Default:
              totext(truncate(Mins/60),0) + ':' + select len(tmp)
          case 1:
                     '0' + tmp
          default:
                     tmp;
)




The above code accepts a numbervar parameter. and returns a string

Your function will be created with the name you give 
As shown below i have two functions created.



You can call this function in your formulas and get a string value in return.

No comments:

Post a Comment