Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Time Conversion into HH:MM:SS Post Reply Post New Topic
Author Message
avishalpatil
Newbie
Newbie


Joined: 24 Dec 2010
Online Status: Offline
Posts: 13
Quote avishalpatil Replybullet Topic: Time Conversion into HH:MM:SS
     Posted: 06 Mar 2014 at 1:43am
Hi All ,

I am having Latency field (Data type Varchar 2(100)) in a database storing values like below

PT1M3S
PT4S
0000:01:46.0
0000:00:03.0

I want to write a formula to convert all above values into HH:MM:SS which mean

00:01:03
00:00:04
00:01:46
00:00:03

Can you please suggest how can i write this in a crystal report ??
Thanks In Advance for your help.

Regards
Vishal
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 10 Mar 2014 at 9:54am
you are going to have to write all the logic. The last 2 are pretty easy, but the first 2 mean nothing to CR. You would have to write the logic to parse and convert to a time.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 11 Mar 2014 at 4:53am
I threw this code together yesterday.  It seems to work okay.  The one place I know that it will not display properly is if there are minutes but no seconds (i.e. PT2M, but will work if PT2M0S).

stringvar tempvar;
if {timedata_txt.Time} startswith "0" then
  tempvar := mid({timedata_txt.Time},6,5)
else
 (if instr({timedata_txt.Time},"M") <>0 then
    if isnumeric(mid({timedata_txt.Time},4,1)) then
        tempvar := mid({timedata_txt.Time},3,2)+":"
    else
        tempvar :=  "0"+ mid({timedata_txt.Time},3,1)+":"
  else
        tempvar := "00:";
  if  instr({timedata_txt.Time},"S") <>0 then
    if isnumeric(mid({timedata_txt.Time},len({timedata_txt.Time})-2,1)) then
        tempvar := tempvar + mid({timedata_txt.Time},len({timedata_txt.Time})-2,2)
    else
        tempvar := tempvar + "0"+mid({timedata_txt.Time},len({timedata_txt.Time})-1,1));
"00:"+tempvar

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