TIMESTAMP columns (by default) set the value to the current date/time on insert and when the row is updated:
http://dev.mysql.com/doc/r
The DATE_FORMAT() function is defined here:
http://dev.mysql.com/doc/r
Main Topics
Browse All TopicsI have a mysql/php application where I need to get the current date and time.
When a record is inserted in the table, I need to save the current date and time and when the record is updated, I need to update the date and time to the new current date and time.
I would then like if possbile to display this info as for example
April 20, 2007 4:00pm
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
TIMESTAMP columns (by default) set the value to the current date/time on insert and when the row is updated:
http://dev.mysql.com/doc/r
The DATE_FORMAT() function is defined here:
http://dev.mysql.com/doc/r
first you need to add a timestamp column in your table and user mysql NOW() function to insert the current datatime.
http://dev.mysql.com/doc/r
Next you need to use php's date function to format the date once you retrive it from the database ...
you could use something like
$date_from_db = strtotime($date_column);
$date = date("M d, Y g:ia",$date_from_db);
Hi
mySQL side
First create a column called "currenttime" (or any name u wish to give). This column should be of type
"timestamp";
Php Side
$now = date("YmdHis");
insert into table t1(name,currentime) values('$name',$now);
for the exact format you are looking for, try this link
http://us.php.net/manual/e
Try it. I hope this works
Sijith
Its very simple to put current date and time in database.
One solution for both field to get update by current value. That is "now()".
I will give you small example .This is the updation query. Plesae try to understand what i am trying to tell you from this Query.
$update_satisfaction_ratio
SET article_date=now(), article_time=now() WHERE article_id=$id"),0,0);
If you have some fields type like Date and Time . Then donot worry just put now() in the value of that like example given above ..
I hope this is the perfect solution for what you are looking for ..
All the best :)
-- RB --
I've tried the above options.
My time is coming out as 3 hours behind my time is. This is probably because my hosting server is in a different time zone. How can I get the correct time.
Also I have using a fetch in my sql to get resutls. Can I format my date and time so it looks like May 22, 2007
Thanks
Business Accounts
Answer for Membership
by: todd_farmerPosted on 2007-04-21 at 19:04:48ID: 18953166
Just use a TIMESTAMP column - you will need to use DATE_FORMAT() function to format the output.