Jump to content

Recommended Posts

i have a form that inputs into a mysql database.

2 of the fields are dates. from and to. ive been trying to search for a way to insert into the database for the days inbetween the dates given and i dont no if to do this in php or the mysql query.

 

$post_a = val1
$post_b = val2
$post_c = val3
$post_d = val4
$post_e = 10/12/2010
$post_f = 15/12/2010

$date = loop of $post_e to $post_f(
10/12/2010 
11/12/2010
12/12/2010 
13/12/2010 
14/12/2010
15/12/2010)
                                   

$sql="insert into $table (a, b, c, d, date) values ('$post_a', '$post_b', '$post_c', '$post_d', '$date') ";

Link to comment
https://forums.phpfreaks.com/topic/221656-insert-into-databae-between-2-dates/
Share on other sites

hmm

so easy i spent 5 hours googling how to do this and came back with nothing usefull.

 

bit like your comment actually.

 

now if somebody can help me out on this and point me in the right direction, your help would be gratefully appreciated.

I had to reformat your date because the strtotime function didn't pick up the format.  Might have to play around with it:

 

ini_set ("display_errors", "1"); 
error_reporting(E_ALL);

$table = "your_table";
$post_a = "val1";
$post_b = "val2";
$post_c = "val3";
$post_d = "val4";
$post_e = "12/10/2010";
$post_f = "12/15/2010";

while (strtotime($post_e) {
   $sql="insert into $table (a, b, c, d, date) values ('$post_a', '$post_b', '$post_c', '$post_d', '$post_e') ";
   echo "$sql\n
";
   $post_e = date("m/d/Y", strtotime("+1 day", strtotime($post_e)));
}

?>

$oneday = strtotime("1 days");

 

$date = strval($post_e);

 

while(abs( strtotime($post_e)  - strtotime($post_f) ) / 86400 <= 1)

{

 

$post_e = strtotime($post_e) + $oneday;

 

$date = $date + "," + strval(date('d/m/Y'),$post_e);

 

}

 

 

echo $date; :P

 

 

 

 

 

maybe your question is wrong  :P

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.