Simple Mysql Now() Question

liunx

Guest
Hi, i'm a bit confused. How can I insert a row using the MYSQL NOW() function so that it only inserts the timestamp and not the timestamp and NOW() Function. I don't want the timestamp to change everytime I update that row. Am I going to have to use a php function to get the date and time stamp into the right format and push that into the database each time, or is there a simple solution to forcing the NOW() only to insert the timestamp. <br /><br />NOTE: My date column is using a timestamp(14) in the form of YYYYMMDDHHMMSS<br />I'f i'm not making any sense let me know...<br /><br />Thanks,<br />Dave<!--content-->
Well, I've noticed that any timestamp fields in MySQL auto-update when anything in the row is changed.<br /><br />My solution for that is something like this:<br /><br />"update `table` set `name`='newvalue', `date`=`date` where `id`='id'"<br /><br />By delcaring "`date`=`date`" it keeps the `date` field the same as it was before.<!--content-->
Thanks for the reply...I'm not sure I understand you. <br /><br />How can I set a date datatype to a character value. <br />date='date' <br /><br />I'm confused...they talk about how to do it exactly here <a href="http://www.mysql.com/doc/en/DATETIME.html" target="_blank">http://www.mysql.com/doc/en/DATETIME.html</a> but what do they mean by setting the timestamp columb explicity to its current value. <br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->You can use this property if, for example, you want a TIMESTAMP to be set to the current date and time when you create a row, but not to be changed whenever the row is updated later:<br /><br />    * Let MySQL set the column when the row is created. This will initialize it to the current date and time.<br />    * When you perform subsequent updates to other columns in the row, set the TIMESTAMP column explicitly to its current value. <br /><br />On the other hand, you may find it just as easy to use a DATETIME column that you initialize to NOW() when the row is created and leave alone for subsequent updates.<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
You mean you want to update the timestamp field manually?<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->update `tablename` set `date`='YYYYMMDDHHMMSS' where `field_id`='field_id'<!--c2--></div><!--ec2--><br /><br />You can do it that way. That way, you can define explicitly what you want the timestamp to be. The way to keep the timestamp exactly the same when other fields in the row are updated is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->update `tablename` set `date`=`date` where `field_id`='field_id'<!--c2--></div><!--ec2--><br /><br />that help any better?<!--content-->
<!--QuoteBegin-TCH-Robert+Jan 27 2004, 09:20 PM--><div class='quotetop'>QUOTE(TCH-Robert @ Jan 27 2004, 09:20 PM)</div><div class='quotemain'><!--QuoteEBegin-->Well, I've noticed that any timestamp fields in MySQL auto-update when anything in the row is changed.<br /><br />My solution for that is something like this:<br /><br />"update `table` set `name`='newvalue', `date`=`date` where `id`='id'"<br /><br />By delcaring "`date`=`date`" it keeps the `date` field the same as it was before.<!--QuoteEnd--></div><!--QuoteEEnd--><br /> Nice. I've been wondering about that. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I have a news script where the date changes if I edit the article. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> They are sorted by id, so it's not been a high prioroty to fix, but I'm glad to know the fix is that easy.<!--content-->
<!--QuoteBegin-TCH-Robert+Jan 28 2004, 09:44 AM--><div class='quotetop'>QUOTE(TCH-Robert @ Jan 28 2004, 09:44 AM)</div><div class='quotemain'><!--QuoteEBegin-->You mean you want to update the timestamp field manually?<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->update `tablename` set `date`='YYYYMMDDHHMMSS' where `field_id`='field_id'<!--c2--></div><!--ec2--><br /><br />You can do it that way. That way, you can define explicitly what you want the timestamp to be. The way to keep the timestamp exactly the same when other fields in the row are updated is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->update `tablename` set `date`=`date` where `field_id`='field_id'<!--c2--></div><!--ec2--><br /><br />that help any better?<!--QuoteEnd--></div><!--QuoteEEnd--><br /> Dude i'm sorry man, but I still don't understand what you want me to do. <br /><br />I'll try to ask my previous question again...<br />You said to set the date field to 'date' ???<br />I said...is that possible..you are trying to add a character value into a date datatype...<br />how is that going to prevent it from updating it...It will likely not accept that value and just default the date to all zeros assuming u have that date field set to not null which I do.<!--content-->
ROFL.... woooot Now i get it, you just set the date field to exactly what it was before....hehehe...You know what was confusing me... your quotes.. I didn't notice they were <!--sizeo:14--><span style="font-size:12pt;line-height:100%"><!--/sizeo-->`<!--sizec--></span><!--/sizec--> i thought they were <!--sizeo:14--><span style="font-size:12pt;line-height:100%"><!--/sizeo-->'<!--sizec--></span><!--/sizec--> ... I was thinking why the hell do you want me to insert the characters 'date' on there....but now I know you meant for me to put the name of my date field instead....<br /><br />hehe... Its all my fault..since i never put those type of quotes to identify my fields...It works fine w/o them,. <br /><br />I'm just glad I finally got it working... Thumbs Up <br /><br />Thanks again robert for your patience.<!--content-->
 
Back
Top