I had some problems with dates between mySQL and PHP. PHP had all these great date functions but I wanted to store a usable value in my database tables. In this case I was using TIMESTAMP(14) <or 'YYYYMMDDHHMMSS'>. This is perhaps the easiest way I have found to pull the PHP usable UNIX Datestamp from my mySQL datestamp stored in the tables:
Use the mySQL UNIX_TIMESTAMP() function in your SQL definition string. i.e.
$sql= "SELECT field1, field2, UNIX_TIMESTAMP(field3) as your_date FROM your_table WHERE field1 = '$value'";
The query will return a temp table with coulms "field1" "Field2" "your_date"
The "your_date" will be formatted in a UNIX TIMESTAMP! Now you can use the PHP date() function to spew out nice date formats.
Sample using above $sql: 20010111002747 = Date Stored on mySQL table (TIMESTAMP(14)) 979172867 = value returned as your_date in sql stmt (UNIX_TIMESTAMP)
if we use $newdate = date("F jS, Y -- g:ia", $row["your_date"]); --(after fetching our array from the sql results of course)--
echo "$newdate"; --Will produce: January 11th, 2001 -- 12:27am
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.