fsl4faisal Posted October 9, 2010 Share Posted October 9, 2010 if($_POST['Submit']=="Check"){ /*$title=mysql_real_escape_string($_POST['title']); $subject=mysql_real_escape_string($_POST['subject']); $author=mysql_real_escape_string($_POST['author']);*/ $bookid=(int)$_POST['bookid']; $account=(int)$_POST['account']; $issuedate=mysql_real_escape_string($_POST['issuedate']); //Sduedate=$issuedate+15; $duedate=DATE_ADD('$issuedate'+interval 15 DAY) print $duedate; print $issuedate; $insert_query="insert into issue values($account,$bookid,'$issuedate','$duedate')"; $result=mysql_query($insert_query,$linkID1); if($result){ print "<html><body background=\"header.jpg\"> <p>book successfully added</p></body></html>"; } else{ print "<html><body background=\"header.jpg\"> <p>$insert_query</p>"; print "<p>there was a problem in adding</p></body></html>"; } } i want $duedate should be 15 days from the issuedate Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/ Share on other sites More sharing options...
jcbones Posted October 9, 2010 Share Posted October 9, 2010 $insert_query="insert into issue values($account,$bookid,'$issuedate',DATE_ADD($issuedate,INTERVAL 15 DAY))"; DATE_ADD is a mysql function, NOT a PHP function. Therefore it must be handled by the DATABASE not the script. Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/#findComment-1120515 Share on other sites More sharing options...
fsl4faisal Posted October 9, 2010 Author Share Posted October 9, 2010 $insert_query="insert into issue values($account,$bookid,'$issuedate',DATE_ADD($issuedate,INTERVAL 15 DAY))"; Its not Working Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/#findComment-1120569 Share on other sites More sharing options...
jcbones Posted October 9, 2010 Share Posted October 9, 2010 Since you have the error outputting to your screen, just fix what is wrong. Otherwise post here the error you are getting, and we could help. Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/#findComment-1120571 Share on other sites More sharing options...
fsl4faisal Posted October 9, 2010 Author Share Posted October 9, 2010 if($_POST['Submit']=="Check"){ $bookid=(int)$_POST['bookid']; $account=(int)$_POST['account']; $issuedate=mysql_real_escape_string($_POST['issuedate']); /*$duedate = new DateTime($issuedate); $duedate->add(new DateInterval('P15D')); echo $duedate->format('Y-m-d H:i:s') . "\n";*/ //$issuedate=date("Y-m-d",$issuedate); echo 'issuedate date is ' . $issuedate; list($year,$month,$date) = explode('-',$issuedate,3); $duedate = mktime(0,0,0,date($month),date(day)+15,date($year)); echo 'duedate date is ' . date("Y-m-d",$duedate); $duedate=date("Y-m-d",$duedate); //print $duedate; print "<br>"; //$issuedate=date("Y-m-d",$issuedate); print $issuedate; print "<br>"; print $year; print "<br>"; print $month; print "<br>"; print $date; $insert_query="insert into issue values($account,$bookid,'$issuedate','$duedate')"; $result=mysql_query($insert_query,$linkID1); if($result){ print "<html><body background=\"header.jpg\"> <p>book successfully added</p></body></html>"; } else{ print "<html><body background=\"header.jpg\"> <p>$insert_query</p>"; print "<p>there was a problem in adding</p></body></html>"; } } mysql> select * from issue; +---------+--------+------------+------------+ | account | bookid | issuedate | duedate | +---------+--------+------------+------------+ | 1 | 1 | 0000-00-00 | 0000-00-00 | | 1 | 1 | 2010-12-12 | 0000-00-00 | | 1 | 1 | 2010-12-12 | 0000-00-00 | | 1 | 1 | 2010-08-12 | 0000-00-00 | | 1 | 1 | 2010-08-12 | 1970-01-01 | | 1 | 2 | 2010-12-12 | 1970-01-01 | | 1 | 2 | 2010-12-12 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-01 | | 1 | 2 | 1970-01-01 | 1970-01-24 | | 1 | 2 | 1970-01-01 | 1970-01-24 | | 1 | 2 | 1970-01-01 | 1970-01-24 | | 1 | 2 | 1970-01-01 | 2010-01-24 | | 1 | 2 | 2010-01-01 | 2010-01-24 | +---------+--------+------------+------------+ now day is increased by 23 i want it to be increased by 15 Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/#findComment-1120591 Share on other sites More sharing options...
jcbones Posted October 9, 2010 Share Posted October 9, 2010 Change: /*$duedate = new DateTime($issuedate); $duedate->add(new DateInterval('P15D')); echo $duedate->format('Y-m-d H:i:s') . "\n";*/ //$issuedate=date("Y-m-d",$issuedate); echo 'issuedate date is ' . $issuedate; list($year,$month,$date) = explode('-',$issuedate,3); $duedate = mktime(0,0,0,date($month),date(day)+15,date($year)); echo 'duedate date is ' . date("Y-m-d",$duedate); $duedate=date("Y-m-d",$duedate); //print $duedate; To: $duedate = date('Y-m-d',strtotime('+ 15 days',strtotime($issuedate))); Link to comment https://forums.phpfreaks.com/topic/215484-help-in-mysql-fuction-date_add/#findComment-1120593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.