Jump to content


Photo

*SOLVED* date update


  • Please log in to reply
1 reply to this topic

#1 eranwein

eranwein
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 04 April 2006 - 10:35 PM

how do i increment a record field which is a type of datetime to be it's initial value plus let's say one year.

i want to use one UPDATE query, and not SELECT and then UPDATE.

for example '2004-11-15 10:11:48' will be 2005-11-15 10:11:48.



#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 05 April 2006 - 01:22 AM

Example:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] table_name SET date_column_name = DATE_ADD(date_column_name, INTERVAL 1 YEAR) WHERE ...
[!--sql2--][/div][!--sql3--]

Leave out the "WHERE" condition to update all rows in the table.

See:
[a href=\"http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#id3216476\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/dat....html#id3216476[/a]

[a href=\"http://dev.mysql.com/doc/refman/4.1/en/update.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/update.html[/a]






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users