MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:KKolle Date:March 16 2003 8:53pm
Subject:RE: Newbie - How can I insert new data with the current date/time?
View as plain text  
Great, this is more of what I was looking for....a way to have the DB auto
populate the date/time in a column, without having to use sql.

Thanks again!


                                                                                          
                        
                    "Uttam"                                                               
                        
                    <uttam@stripped.       To:     <KKolle@stripped>,
<mysql@stripped>                  
                    in>                  cc:                                           
                           
                                         Subject:     RE: Newbie - How can I insert new
data with the current      
                    03/16/2003            date/time?                                      
                        
                    02:10 AM                                                              
                        
                                                                                          
                        
                                                                                          
                        




*if you create a column of the type TIMESTAMP instead of DATETIME then it
automatically stores the time when the record was inserted/last updated.  If
you have more that one column of type TIMESTAMP in the same table then only
the first TIMESTAMP column gets updated automatically. (Don't confuse MySQL
TIMESTAMP column type with Unix Timestamp, MySQL TIMESTAMP column is just an
automatically updated DATETIME column)

*to insert current datetime in a DATETIME column, use NOW() or SYSDATE().
e.g.
INSERT INTO bug_master VALUES (1, "Timothy", NOW())

regards,

-----Original Message-----
From: KKolle@stripped [mailto:KKolle@stripped]
Sent: Saturday, March 15, 2003 20:08
To: mysql@stripped
Subject: Newbie - How can I insert new data with the current date/time?


I have a table called animals (using the example in the MySQL guide). I
have a
datetime column type.
Here is the table:
create table bug_master (
               id MEDIUMINT NOT NULL AUTO_INCREMENT,
               name CHAR(30) NOT NULL,
               date DATETIME NOT NULL,
               PRIMARY KEY (id)
          );

I want to do a simple insert into the table with the current date and
time, i.e.
the system date.
I'm having some problems finding the correct sql syntax to do this.
Could anyone
help with this?
Do I need a Now() function?

insert into animals <the rest of the query??>;

Thanks!
Kevin







Thread
Newbie - How can I insert new data with the current date/time?KKolle15 Mar
  • Re: Newbie - How can I insert new data with the current date/time?Paul DuBois15 Mar
  • RE: Newbie - How can I insert new data with the current date/time?Uttam16 Mar
Re: Newbie - How can I insert new data with the current date/time?KKolle16 Mar
RE: Newbie - How can I insert new data with the current date/time?KKolle16 Mar