Formatting Time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
aquanutz
Forum Commoner
Posts: 28
Joined: Thu Sep 14, 2006 9:07 am

Formatting Time

Post by aquanutz »

Is there any quick way to bring back a time as just '8 am' instead of '08:00 AM' in MySQL?

This is what I have thusfar that brings back the ladder of the above:

Code: Select all

TIME_FORMAT(monO, '%h:%i %p') as monO
Thanks for any input.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

TIME_FORMAT(monO, '%h%p') as monO
??
aquanutz
Forum Commoner
Posts: 28
Joined: Thu Sep 14, 2006 9:07 am

Post by aquanutz »

Haha, yeah that works. I always fail to see the blatantly obvious.

I guess the real thing I need it to do is drop that preceeding '0' off the time so i get '8:00 am' instead. I've been looking and I don't think that I can bring it back like that, which means I'll just write a php function to take care of it.

Probably just better to write something myself because some times are 1-9 and some are 10-12 with :30 or :00 on the end.. and if it's just '08:00 AM' I just want '8 am' but if it has the :30 on the end I want that there too... from what I've read, sql can't do anything like what I need.

Anyhow, thanks for your reply.
aquanutz
Forum Commoner
Posts: 28
Joined: Thu Sep 14, 2006 9:07 am

Post by aquanutz »

yeah, i just wrote my own script to do it.

CLOSED
Post Reply