Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to add time and date to mysql

0 views
Skip to first unread message

Dark Angel

unread,
Dec 21, 2003, 6:14:21 PM12/21/03
to
below is a working code to insert information form the form, but on the date
part, I would like to add a time and date in to the timestamp tag of the
mysql db.
What I want to know is in the mysql db what should it be?
timestap
date and time
UNIX time etc...
and the last part of this code is $date how would I get this to add to the
db?
The verable for the is $date is $date = date();
$sql = "INSERT INTO phpBlog (`id`, `name`, `comment`, `timestamp`) VALUES
('', '$_POST[name]', '$_POST[comment]', '$date')";

Any help would be much a predated.

BTW even thought I'm only a beginner in this, I would like to say that php
is brilliant :)

--
Best Regards
Dark Angel

--------------------------------------------------------------------------
http://www.stateofmind.me.uk - My Home Page
http://www.keir.net/k9.html - Free spam filter for windows
http://www.shrine2aeris.co.uk - My shrine to Aeris from FF7


Janwillem Borleffs

unread,
Dec 22, 2003, 5:04:28 AM12/22/03
to

"Dark Angel" <nights...@hotmail.com> schreef in bericht
news:HVpFb.4$7v...@news-binary.blueyonder.co.uk...

>
> and the last part of this code is $date how would I get this to add to the
> db?
> The verable for the is $date is $date = date();
> $sql = "INSERT INTO phpBlog (`id`, `name`, `comment`, `timestamp`) VALUES
> ('', '$_POST[name]', '$_POST[comment]', '$date')";
>

When you do an
"alter table phpBlog change timestamp timestamp timestamp(14)"

Dates and times are automatically stored in YYYYMMDDHHMMSS format.

The sql query would then be:
$sql = "INSERT INTO phpBlog (`name`, `comment`) VALUES
('{$_POST['name']}', '{$_POST['comment']}')";

BTW, when the id field has auto_increment enabled, you don't have to specify
it in the query.

See http://www.mysql.com/doc/en/DATETIME.html for more info.


JW

0 new messages