FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Reformatting a DATETIME MySQL value after retrieving via PHP





Solugon
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?
hexkid
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);
Solugon
Ah, ok, thanks.
bladesage
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.
Solugon
I just made a function to parse the DATETIME and reformat it. Laughing
Related topics
Tutorial: PHP Installed Modules Dynamic Reference Tool
an annoying problem - PLEASE help
Need some php/mysql dlls
[PHP] Running Cron Jobs Via PHP Script
A very good PHP MySQL Tutorial
Sending email via PHP
AJAX tutorial [2nd part now updated]
What is the best way to save a date/timestamp in mysql
Envoi de mail via PHP sur frihost
Database Privilege
PHP/MySQL challenge, take it if you dare
How to grant user in mysql via PHP script
PHP Login-Script (With Sessions)
Can ASP be used with XAMPP?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.