How can I use PHP to display a MYSQL datetime value without displaying the seconds?
November 28, 2006 7:24 AM
Subscribe
How can I strip the seconds off when displaying a MYSQL datetime variable, using only PHP commands, not MYSQL commands like "DATE_FORMAT"?
I have a form where users enter a few dates and times. I don't care about seconds, just the year, month, day, hours, minutes. I'm using PHP with MYSQL, and the MYSQL values are in datetime format.
When I display the contents of those variables, it shows them as, for example:
2006/11/28 17:26:00
What I would like displayed is:
2006/11/28 17:26
I know this can be done with the DATE_FORMAT command in a MYSQL query, but the problem is that I have quite a few queries, all in the form of "SELECT * FROM table WHERE blahblahblah" (which gathers lots of other information besides datetimes), and if I make separate queries in the form "SELECT DATE_FORMAT (startTime, blahblahblah) AS startTime" for all the time values I call up, I'm going to be making my code much longer and harder for other people (who, like myself, are non-programmers with limited PHP knowledge) to work on.
Is there any way that's relatively clean/simple on the PHP end to take, for example, a variable called $startTime, with a value like "2006-11-11 12:13:00", and display it on a page as "2006-11-11 12:13"?
Yes, I have Googled like a motherfucker, but to no avail.
posted by Bugbread to computers & internet (14 comments total)
Also, investigate the date() function, eg
date ("H:m:00", $unix_timestamp);
posted by Leon at 7:30 AM on November 28, 2006