ohdang888 Posted January 21, 2008 Share Posted January 21, 2008 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? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 21, 2008 Share Posted January 21, 2008 I'm not sure if it's possible, but you could try to set the default to NOW(). Otherwise explicitly make the date that. Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted January 21, 2008 Author Share Posted January 21, 2008 how do i use "now()"???? like.... $datetime = function(now()) ???? Quote Link to comment Share on other sites More sharing options...
mike177 Posted January 22, 2008 Share Posted January 22, 2008 how do i use "now()"???? like.... $datetime = function(now()) ???? I'm not expert ohdang888 but thats not how you would use it. You need to give the function a name first then you () then {} to open and close. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted January 22, 2008 Share Posted January 22, 2008 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! Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 22, 2008 Share Posted January 22, 2008 Ohdang!!! this is double post !!!! :-\ I want to add something on this thread because i believe I know the problem but I'm confused where to place my post should i post it here or in your second post.. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 22, 2008 Share Posted January 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
beebum Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.