Learn PHP The Easiest Way To Insert Time And Date Into Mysql Database Table

RegisterLogin
Learn PHP The Easiest Way To Insert Time And Date Into Mysql Database Table
Post Description: Learn PHP The Easiest Way To Insert Time And Date Into Mysql Database Table
Tags: Learn, PHP, The, Easiest, Way, To, Insert, Time, And, Date, Into, Mysql, Database, Table
This Post Was Posted On Feb 29, 2008 By web hosting #1478
if you are asking yourself this question also, I may have the answer for you. I found the easiest way to enter or insert the time and date automatically into mysql is with the now() function. In this short simple tutorial guide i will show you steps to take to insert the time and date with the year month day hour and even seconds into a mysql database.

first make sure you have mysql database, if you don't have mysql on your website, you can visit our friends at www.webune.com and signup with one of their plans.

so, to insert the time and date inot my tables i use this sql query:



     Code:
$sql = "INSERT INTO table-name(field_name) values (now())'";


if is do the query above, the system will enter a time stamp of "2007-04-04 21:48:37" which is right now..

you also have to make sure that you create the field correctly. you can use this table as and example:


     Code:
CREATE TABLE `post`
(
`post_date` datetime NOT NULL default '0000-00-00 00:00:00',
)


I find that this is the best and easy way to inster the time and day of the current (present) year month day hour and seconds of today.
Leave Your Comments
visualmano
#2639 1
thanks for the how to add date/time to my already made php database table, i didnt know i could insert time and date like that
Oct 25, 2009 Reply Report abuse
omar
#2547 2
is this the best way to insert date mysql php?
Oct 10, 2009 Reply Report abuse
webune
#1916 3
php code to insert current date into mysql database. there are alot of php mysql resources even in a mysql_query you can do php mysql database script which i only know how to do is php sql mysql php mysql database tutorials and this is a good one using php mysql echo

like for example: mysql_fetch_array
php mysql datetime
php mysql mysql_connect

for example lets say i want to send a quiery:

$sql = "insert into mydatabase set time = ".time().";

as you can see you can use the time() function in php

hope that helps
Aug 05, 2009 Reply Report abuse
Leave Your Comments...
©2011 Webune Forums - Mon Dec 19, 2011 9:17 pm
Powered by: Webune Forums V3