Reputation: 1634
I have a data base table containing a id, description, start_date, end_date
there are 12 entries for every month i just want to increment year 2012 to 2013 in every start_date, end_date
field when this year end is it possible when a super user login check date and if it is 01-01-20xx
update year only in database table.
Upvotes: 0
Views: 1779
Reputation: 13785
Working
UPDATE Table_name SET start_date = DATE_ADD(start_date,INTERVAL 1 YEAR), end_date = DATE_ADD(end_date,INTERVAL 1 YEAR) WHERE id = '';
Upvotes: 0
Reputation: 1634
$query="UPDATE awards_list SET start_date = start_date + interval '1 year',
end_date = end_date + interval '1 year'";
Iam also using postgressql in that this worked perfectly and i got it through a click button i.e when click on button the entire table year fields will increment by 1 year so one click for one year is enough.
Upvotes: 0
Reputation: 12169
You can try the following:
UPDATE Table_name SET start_date = DATE_ADD(start_date,INTERVAL 1 YEAR), end_date = DATE_ADD(end_date,INTERVAL 1 YEAR) WHERE id = '';
Upvotes: 1
Reputation: 2615
Try This
<?php
$currentyear=date("Y");
//check the year database value
$yearindatabase=2012;//from database
if($currentyear>$yearindatabase)
{
for($i=1;$i<=12;$i++)
{
$num = cal_days_in_month(CAL_GREGORIAN, $i, $currentyear);
$start_date="2012-".$i."-01";
$end_date="2012-".$i."-".$num."";
//Update Query
$queryUpdate="update table set start_date='".$start_date."',end_date='".$end_date."'";
}
?>
Upvotes: 0