Currently, I'm taking the time and sending it to the database, then retrieving it and printing it onto the page, but I need a way to change the format of it from 0000-00-00 00:00:00 (year-month-day hour:minute:second) to something of the format "n/j/Y g:i a". Any idea how to do that?
Reformatting a DATETIME MySQL value after retrieving via PHP
| Solugon wrote: |
| Currently, I'm taking the time and sending it to the database, then retrieving it and printing it onto the page, but I need a way to change the format of it from 0000-00-00 00:00:00 (year-month-day hour:minute:second) to something of the format "n/j/Y g:i a". Any idea how to do that? |
SQL
| Code: |
| select unix_timestamp(date_column) |
PHP
| Code: |
| echo date('your format', $value_from_database); |
Ah, ok, thanks.
| Solugon wrote: |
| Ah, ok, thanks. |
I'd suggest you change the fields containing the date to an INT(32) data type field. When inserting into the table, you can use the raw integer provided by the time() function. Then when you want to extract it from the database, you get back a timestamp, which can easily be formatted however you want it, using
| Code: |
| date('n/j/Y g:i a', $date); |
This assumes that the variable containing the database timestamp that you selected in the query is $date, change however you like.
I just made a function to parse the DATETIME and reformat it. 
