Jump to content

date-time


ohdang888

Recommended Posts

when a row is inserted into the datase, there is a column that i want to make it automatically store the date and time it was inserted.

 

so i used datetime on the TYPE option...

 

but everything is coming up as 0000-00-00 00:00:00

 

do i need to use a datetime code in the script too? what it is if i do?

Link to comment
https://forums.phpfreaks.com/topic/87125-date-time/
Share on other sites

no I believe the now() function is used in the actual mysql column. So when creating your mysql table you setup the column type to time stamp and then have a function in it saying now().

 

I think that makes sense!

 

Yes, NOW() is a MySQL function.

 

See: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now

Link to comment
https://forums.phpfreaks.com/topic/87125-date-time/#findComment-445866
Share on other sites

CREATE TABLE mytable (

...column_defs_here

  DT_inserted timestamp NOT NULL default CURRENT_TIMESTAMP,

...any_other_defs_here

);

 

INSERT INTO mytable (col1, col2...) values ('col1val', 'col2val',...);

 

Do not insert values for "DT_inserted" column or for an auto_increment column, these will be inserted automatically.

Link to comment
https://forums.phpfreaks.com/topic/87125-date-time/#findComment-446276
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.