I store my datetime values as, for example, “2011-01-06 22:46:40”, but want them to display as “Jan 06, 2011 at 10:46 PM”. I have fiddled around with PHP’s date functions but can’t get exactly what I am looking for, probably because I am a moron. Please help me!
@NogDogJan 07.2011 — #If you are pulling them out of a MySQL database, use the DATE_FORMAT() function in your SQL statement to get the desired format (assuming it is a datetime or timestamp type column). Otherwise, you can convert it within PHP to a UNIX timestamp via the strtotime() function, then convert that value to the desired string format via date().
@bubbisthedogauthorJan 07.2011 — #If you are pulling them out of a MySQL database, use the DATE_FORMAT() function in your SQL statement to get the desired format (assuming it is a datetime or timestamp type column). Otherwise, you can convert it within PHP to a UNIX timestamp via the strtotime() function, then convert that value to the desired string format via date().[/QUOTE]
nog, you've helped me with a lot of stuff, and i thank you for that. And this is no exception. In this case I would rather not convert the date/time in my SQL statements, and rather format them as they need to be printed using PHP. I tried many variations of convert it within PHP to a UNIX timestamp via the strtotime() function, then convert that value to the desired string format via date()[/QUOTE] The problem is that I cannot figure out how to get it to print exactly what I want to print. I really have tried; I just can't get it to work...
@bubbisthedogauthorJan 07.2011 — #nog, Criterion, THANKS for taking the time to help me. I was not including the strtotime() function obviously. Never really worked with converting dates in PHP so now I know!
@bubbisthedogauthorJan 07.2011 — #[code=php] $query = SELECT UCASE( DATE_FORMAT(Publish_Up,'%b %d, %Y %l:%i %p'))AS publishDate FROM table WHERE ...";
//do some query stuff
echo $row['publishDate']; [/code]
I have no problem formatting it in MySQL works great,[B] likely faster than in PHP processor.[/B][/QUOTE]
That, Dasher, I will keep in mind, and will explore in the future. :-) For now I'd rather just use a very simple PHP function to convert the date and leave the queries 'clean', if you will.
@DasherJan 10.2011 — #FYI - I have done MySQL queries that are nearly 1000 characters long. MySQL still processes them amazing fast. Formating text or date strings in MySQL is a piece of cake compared to some much more complex processes it can handle.
@bubbisthedogauthorJan 13.2011 — #FYI - I have done MySQL queries that are nearly 1000 characters long. MySQL still processes them amazing fast. Formating text or date strings in MySQL is a piece of cake compared to some much more complex processes it can handle.[/QUOTE]