Reputation: 1
Im trying to get my commentbox to post the current time after the comment, but the old comments keep changing time to the current time. I want it to show the time of the post and i dont know how to do.
$date = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
echo $name . '<br/>' . '<br/>' . $comment . $date->format('d-m-Y H:i:s') . '<br/>' . '<br/>' . '<hr size="1"/>'
Upvotes: 0
Views: 115
Reputation: 219874
The first parameter of DateTime()
needs to be the date of the comment. If it always says "now" it will always be the current date/time.
Assuming you called the row from your database query $row
and the column in the database is called datefromdatabase
your code would look like this:
$date = new DateTime($row['datefromdatabase'], new DateTimeZone('Asia/Kolkata'));
Upvotes: 1