Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: converting a string to a time field Post Reply Post New Topic
Author Message
STATS1
Newbie
Newbie


Joined: 24 Oct 2011
Online Status: Offline
Posts: 4
Quote STATS1 Replybullet Topic: converting a string to a time field
     Posted: 11 Jun 2012 at 11:24am
Hi there,
 
I am trying to convert a time field that is showing up as a string such as (955, 1955, or 131955) and wanting to convert it to a millitary time field such as (00:09:55, 00:19:55, 13:19:55).
 
Is there one formula in crystal that will handle all scenarios and easily convert them to the millitary time?
 
Thanks so much!
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 11 Jun 2012 at 6:17pm
No guarantees as I'm not real good with formulas but  CStr(#3:20:30 PM#,"HH:mm:ss")  should work.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Jun 2012 at 3:44am
If you don't want to convert it to a time field this might work...
 
picture(right("000000" + {table.field},6),"xx:xx:xx")


Edited by DBlank - 12 Jun 2012 at 3:45am
IP IP Logged
STATS1
Newbie
Newbie


Joined: 24 Oct 2011
Online Status: Offline
Posts: 4
Quote STATS1 Replybullet Posted: 13 Jun 2012 at 5:07am
Hmmm..no luck with trying the last two ideas, but thanks for trying.  As an update, the field isn't a string, it is actually coming accross as a number, but I just want to add the two ':' ':' in it.  Any other thoughts for a formula which will do this?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2012 at 5:13am
picture(totext({table.numericfield},"000000"),"xx:xx:xx")
IP IP Logged
STATS1
Newbie
Newbie


Joined: 24 Oct 2011
Online Status: Offline
Posts: 4
Quote STATS1 Replybullet Posted: 13 Jun 2012 at 5:33am
Further to my last post, I tried entering for a formula:  Time({field})
 
It comes out the way it should:  00:00:00 but I am only getting zeros, I am not actually getting the correct time...
 
Any other thoughts?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2012 at 5:46am
did you try
picture(totext({table.numericfield},"000000"),"xx:xx:xx")
?
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 13 Jun 2012 at 5:48am
As it's a number (ie no preceeding 0s for single digits) how do you determine which number relates to which unit of time?
 
youe example above, 955, the 9 is a single digit, doesn't that mean if the seconds was a single digit there'd be no leading 0?
 
eg a value of 135, without leading 0s the value could equate to either of the following;
 
00:13:05
or
00:01:35
 
Thanks,
Ryan.
IP IP Logged
STATS1
Newbie
Newbie


Joined: 24 Oct 2011
Online Status: Offline
Posts: 4
Quote STATS1 Replybullet Posted: 15 Jun 2012 at 5:27am
SmileSmile
Yay!!
 
picture(totext({PIPDPM.PMADM#},"000000"),"xx:xx:xx")
 
This worked!!!!
 
Thanks so much!!
 
 
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