Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: String to time Post Reply Post New Topic
Author Message
louisville2k10
Groupie
Groupie
Avatar

Joined: 13 Sep 2010
Location: United States
Online Status: Offline
Posts: 45
Quote louisville2k10 Replybullet Topic: String to time
     Posted: 20 Dec 2010 at 4:48am
I've got a field that is a string and appears like, "XXX:XX:XX." This is the format I like, but it won't work when I try to summarize multiple fields in the report footer (because it's a string and not a time). To get it into the time format, I've tried CTime({FieldString}) and it returns with an error saying "Bad Format Time String." Can someone provide me with some much-needed insight here?
 
Thanks!
Thanks for your help!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Dec 2010 at 4:54am
You can't do much with a summarization on a time field either...What are you trying to get at?
IP IP Logged
louisville2k10
Groupie
Groupie
Avatar

Joined: 13 Sep 2010
Location: United States
Online Status: Offline
Posts: 45
Quote louisville2k10 Replybullet Posted: 20 Dec 2010 at 5:00am

Here's what I'm working with:

12:45:22 (string)
102:45:45 (string)
42:23:00  (string)
 
I want to somehow summarize these to get a field I will put into the report footer to return: "157:54:07."
 
The problem is that I can't summarize the strings because they're non-numerical. I thought a possible solution would be to convert the strings into time fields, so that I could then summarize the time fields. When I tried to convert the string field to a time field, it returned the error (described above).
 
Can you help me figure out how to convert the string to a time field that I can then summarize?
 
Thanks!


Edited by louisville2k10 - 20 Dec 2010 at 5:00am
Thanks for your help!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Dec 2010 at 5:04am
so you want a total amount of time from all of them?
YOu would have to convert the strings (time) into a number that is the lowest time value you want to look at (minutes or second as I do not know ehich I am looking at in your sample)
Then add these values togther at a group of report footer level.
Then convert that back into whatever dispaly string you want.
Note you are getting the bad format as some of those strings are non existent time values


Edited by DBlank - 20 Dec 2010 at 5:05am
IP IP Logged
louisville2k10
Groupie
Groupie
Avatar

Joined: 13 Sep 2010
Location: United States
Online Status: Offline
Posts: 45
Quote louisville2k10 Replybullet Posted: 20 Dec 2010 at 5:57am

I think I follow your logic, but I don't follow the instructions. How would I "convert the strings into a number that is the lowest time value" (this is seconds for me)?

Thanks for your help!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Dec 2010 at 6:12am

assuming all of your strings have 2 colons then you would do something like:

tonumber(left(field,instr(field,':')-1)) *3600 +
tonumber(mid({field},instr({field},':')+1,len({field})-instrrev({field},':'))) * 60 +
tonumber(right({Field},len({Field})-instrrev({Field},':')))
 


Edited by DBlank - 20 Dec 2010 at 6:12am
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