MySql auto TIME_STAMP not working

I created a table where I set the column payment_time

, TIMESTAMP DEFAULT CURRENT_TIMESTAMP

when creating a table.

When I insert values, I set payment_time

to space with ''

. However, when I checked the table for payment_time, it shows 0000-00-00 00:00:00 where I am looking for the current time. Am I making a mistake here?

+3


source to share


2 answers


try it

     payment_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

      

and change your insert status this way

    INSERT INTO TB (`payment_time`) VALUES ('NOW()' ); 
--dont specifie the id column  it will be automatically inserted

      



EDIT.

 INSERT INTO TB (`col1`, `col2`,`payment_time`) VALUES ('somevalue1','somevalue2','NOW()' ); 
 -- dont use the id column just the other columns , and be sure that columns are in right ORDER

      

due to your edited question here is the solution

INSERT INTO donors (firstName,lastName,gender,email,amount,currency)VALUES(  'MD.Borhan', 'Safa', 'm', 'borhansafa@yahoo.com', '5', 'GBP' );

      

+1


source


payment_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

      



Use this and then don't use payment_time

in the insert statement. The current date will be automatically assigned to your corresponding entry.

0


source







All Articles