Print Page | Close Window

Time format programming

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=9213
Printed Date: 07 May 2024 at 2:30am


Topic: Time format programming
Posted By: rvwinkle
Subject: Time format programming
Date Posted: 24 Feb 2010 at 7:31am
my field prints the time as "1700" but I need it to read as "5:00 pm".  Can someone tell me how to format this field?


-------------
Thanks,
Kim M, Toronto, Canada



Replies:
Posted By: kevlray
Date Posted: 24 Feb 2010 at 7:36am
I do not know of a direct way of doing it.  I have always created a formula.  Basically something like this.  You did not tell us the data type for the time, I am assuming it is a number.  I am not adding the code to put in the ':'.
 
if time >= 12 then totext(time) + " pm"
else totext(time) + " am"
 
I hope this helps.


Posted By: DBlank
Date Posted: 24 Feb 2010 at 7:38am
Is it an actual time field?
If so just right click on it and select Format Field, select the Date and Time tab then select '1:23 pm' as the style.


Posted By: kevlray
Date Posted: 24 Feb 2010 at 7:48am
Duh!  I was thinking it as a number field or a string.


Posted By: rvwinkle
Date Posted: 24 Feb 2010 at 7:50am

It looks like it's not an actual time field as that option is not there. It is a string. That's why I need the formula instead.



-------------
Thanks,
Kim M, Toronto, Canada


Posted By: rvwinkle
Date Posted: 24 Feb 2010 at 7:52am
Kevlray:  nope didn't work. must be because it's a string field.

-------------
Thanks,
Kim M, Toronto, Canada


Posted By: kevlray
Date Posted: 24 Feb 2010 at 8:00am

Is there a leading zero in the time field for values < 1000?



Posted By: DBlank
Date Posted: 24 Feb 2010 at 8:01am

is it always a length of 4?

Convert it using a formula
time(left(timefield,2)+':'+right(timefield,2) +':00')
 
then convert the look as needed as I indicated before.


Posted By: rvwinkle
Date Posted: 24 Feb 2010 at 8:06am
Thank-you
Thank-you
Thank-you
 
That worked!  I am so glad I found this forum. You guys were great and thanks for responding so quickly.
 
Cheers!Clap


-------------
Thanks,
Kim M, Toronto, Canada



Print Page | Close Window