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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, typo:
substr(<string>, 0, -3);
substr(<string>, 0, -3);
ASKER
Worked great! Thank you!!
substr(<string>, 0, 03);