For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2004 > Re: [PHP-DB] Inserting a date in to DATE field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Inserting a date in to DATE field
George Patterson

2004-04-22, 10:30 pm

On Fri, 23 Apr 2004 01:32:36 +0000
"Pambos Nicolaou" <pambos_15@hotmail.com> wrote:

> Hi everyone,
>
> Is there any MySQL command which inserts the date into a DATE field of
> a table automatically. For example the user inserts into the table
> several values (name, age, etc) and the date is inserted
> automatically.
>


Pambos,

Short answer not really.

You can get around it by using a timestamp data type. in you insert query, don't worry about setting the timestamp to a value and mysql will set it to the time and date as the time that the record was inserted.

The other way is to alter your insert queries to
insert into table set .... date_field=now()

George Patterson
John W. Holmes

2004-04-22, 10:30 pm

Pambos Nicolaou wrote:

> Is there any MySQL command which inserts the date into a DATE field of a
> table automatically. For example the user inserts into the table several
> values (name, age, etc) and the date is inserted automatically.


Set the column equal to NOW() or use a TIMESTAMP column (which will be
set to NOW() when the row is created or updated unless you specify a
specific value).

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com