CTime({ado.x}) returning "12:00 AM" for all {ado.x}

CTime({ado.x}) returning "12:00 AM" for all {ado.x}.  The CTime function takes number or string arguments.  My argument is an integer that can range from 0 to 2399.  No matter what the integer value, CTime is returning "12:00 AM"!  This doesn't do what I think it should do.  All I want is for it to return the time on a 12-hour clock.

By the way...

I checked Format Field and the sample at the bottom of the Date/Time tab is the correct time format I desire.  

I've tried CTime(CStr({ado.x})) and get a bad time format string.

I've also IsTime({ado.x}) and it's returned True.  

So what gives???  Please help.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Where are you using this function?

What version of Crystal?

MariaHaltAuthor Commented:
In a formula in my Crystal report.  Version 8.5.
Can you provide some sample values for {ado.x}?  

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

MariaHaltAuthor Commented:
They range from 0 to 2359.  Like, 930, 1100, 1415, 2130.
Try this:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MariaHaltAuthor Commented:
OK that makes more sense now.  You originally listed 0 to 2359.

I am assuming then that:

930 = 9:30 am
1100 = 11:00 am
1415 = 2:15 pm
2130 = 9:30 pm

I assume that whole hours such as 1:00 pm are listed as 1300 and 9:00 am as 900.
The integer stores time in military format with hours and minutes only.

If my assumptions are correct then you can do the following:
Create a formula as follows:
if len(totext({Ado.x})) = 4 then TimeSerial(0,(tonumber(right(totext({Ado.x}),2))),(tonumber(left(totext({Ado.x}),2))*3600)) else
if len(totext({Ado.x})) = 3 then TimeSerial(0,(tonumber(right(totext({Ado.x}),2))),(tonumber(left(totext({Ado.x}),1))*3600)) else
if len(totext({Ado.x})) = 2 then TimeSerial(0,{Ado.x},0) else

Put the formula in the report and it should give you what you are looking for.  I am sure there are other ways of getting the same results.  This is just what came to mind.

MariaHaltAuthor Commented:
Your assumptions are correct.  And I did mistakenly say 2399 instead of 2359 in my original post.  I've accepted bdreed35's answer.  Thanks.
NP, I did not refresh my browser before posting.  :-)  His answer is much better.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.