Forum Moderators: coopster
Something like:$timeval = strtotime($row['date']);
$newdate = date("F j S, Y",$timeval);
echo $newdate;
You may want to consider storing the PHP time() value in your database as an INT(11) instead of using mysql's built in datetime format.
you don't have to input a current time at all. why not use a timestamp field [mysql.com] in your database which automatically inserts the current time everytime you insert or update the row in question. when selecting this field from your database, if, for example, your timestamp field is called 'date' use
select x, y, z, UNIX_TIMESTAMP(date) as date from table_x where bla = bla
this returns your timestamp field as a unix timestamp which you can then format in any way you like using the date() [nl.php.net] function.
this has the advantage that
a) you never have to bother inserting the current time as mysql does it automatically every time you insert or update a row
b) you retrieve the field as a unix timestamp which is easily formateable using date() without the strtotime step
have a read of the links above, everything you could possible need is there.
good luck
I even tend to split date cols and time cols a lot of the time if I use the values seperately and it save s some processing.
The problem I have with timestamp cols is that if you alter the table or have a function that affects every row then all your timestamps get changed. I have had probs with this a few times in the past.
There are also tricks like having two timestamp cols and mysql will only ever update the first one and the second stays protected. This does work for date created and last modified setup but I think an alter table still changes them both, I cant quite remember.
$date= $row['date'];
$timeval = strtotime($date);
$newdate = date("F jS, Y",$timeval);
SELECT DATE_FORMAT(datefield, '%M %D, %Y') as date FROM table WHERE ...
I just converted a program I wrote to do all date formatting like this and it sped it up way more than I expected.
Also, make sure your feild type is DATETIME.