Jump to content

help in mysql fuction DATE_ADD()


fsl4faisal

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.