Link to home
Start Free TrialLog in
Avatar of CynderWolve
CynderWolve

asked on

Formatting mySQL Time Field with PHP?

I have a PHP program that pulls from a mySQL database.  There is a Time field, which is automatically stores the data in a HH:MM:SS format.  However, I want to drop the seconds, so I display the information only in a HH:MM format.

I tried using the date() format function, with the time from the database placed in as the variable - but it came off as an incorrect time, and I'm not sure why.  So then I started thinking I could just remove the last three characters - the last :00 .  But I am having troubles figuring out how to do this.

So how do I do this?  I'd prefer learning about how to ge the date() function to work with a time field, since that will give me more flexibility in the long run.  However, learning how to trim off the last three characters would also be useful.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To trim the last three characters, if you need to use that route, is

substr(<string>, 0, 03);
Sorry, typo:

substr(<string>, 0, -3);
Avatar of CynderWolve
CynderWolve

ASKER

Worked great!  Thank you!!