Jump to content

Need help, start date and end date, i want the in between please.....


redarrow

Recommended Posts

I just slapped this code together, and i want the code to get the start date and end date, then show the in between dates...

 

 

let say you select a start  day month then year then select a end day month and year, i want to get all the dates from start to end.........

 

how can i do that please......

 

you can all use the example, if it helps.

 

advance thank you.

 

 

<?php


if(isset($_POST['submit'])){


$start_date=$_POST['sday'].$_POST['smonth'].$_POST['syear'];

$end_date=$_POST['eday'].$_POST['emonth'].$_POST['eyear'];


echo "<b> <center> The start date is:\n $start_date & End date is:\n $end_date </center>";
}


$php_self=$_SERVER['PHP_SELF'];

echo"<form method='POST' action='$php_self'>";

echo"<table align='center' border='0'><tr><td align='center'>";

echo"<table border='0'><tr><td align='center'>";

//START DATE

echo"<table border='4'><tr><td align='center'>Start Date</td></tr>";

echo"<td><select name='sday'><option>Day</option>";

$day_array=range(1,31);

foreach($day_array as $day){
    	
echo " <option value='$day'>$day</option>";
}

echo"</select>";

echo"<select name='smonth'><option>Month</option>";

$month_array=array("January","Febuary","March","April","May","June",
                   "July","August","September","October","November","December");

foreach($month_array as $month){
    	
echo "<option value='$month'>$month</option>";
}

echo"</select>";

echo"<select name='syear'><option>Year</option>";

$year_array=array("2009","2010","2011","2012","2013","2014","0215");

foreach($year_array as $year){
    	
echo "<option value='$year'>$year</option>";
}

echo"</select></td></tr></table>";

echo"<td>";

//END DATE

echo"<table border='4'><tr><td align='center'>End Date</td></tr>";

echo"<td><select name='eday'><option>Day</option>";

$day_array==range(1,31);

foreach($day_array as $day){
    	
echo "<option value='$day'>$day</option>";
}

echo"</select>";

echo"<select name='emonth'><option>Month</option>";

$month_array=array("January","Febuary","March","April","May","June",
                   "July","August","September","October","November","December");

foreach($month_array as $month){
    	
echo "<option value='$month'>$month</option>";
}

echo"</select>";

echo"<select name='eyear'><option>Year</option>";

$year_array=array("2009","2010","2011","2012","2013","2014","0215");

foreach($year_array as $year){
    	
echo "<option value='$year'>$year</option>";
}

echo"</select></td></tr></table>";
echo"</td>";
echo"</tr></table>";

echo"<br> <input type='submit' name='submit' value='Send!'>";
echo"</td>";
echo"</tr></table>";

echo "</form>";

?>

Link to comment
Share on other sites

Can you explain that very nice example please and cheers....

 

babyish the better explained

 

 

so now it does what i want except need to alter a bit to add the dates to the database and user's id.

<?php


if(isset($_POST['submit'])){


$start_date=$_POST['sday'].$_POST['smonth'].$_POST['syear'];

$end_date=$_POST['eday'].$_POST['emonth'].$_POST['eyear'];


for($i=strtotime($start_date); $i<=strtotime($end_date); $i+=86400) echo date("d-m-Y",$i)."<br />";

}


$php_self=$_SERVER['PHP_SELF'];

echo"<form method='POST' action='$php_self'>";

echo"<table align='center' border='0'><tr><td align='center'>";

echo"<table border='0'><tr><td align='center'>";

//START DATE

echo"<table border='4'><tr><td align='center'>Start Date</td></tr>";

echo"<td><select name='sday'><option>Day</option>";

$day_array=range(1,31);

foreach($day_array as $day){
    	
echo " <option value='$day'>$day</option>";
}

echo"</select>";

echo"<select name='smonth'><option>Month</option>";

$month_array=array("January","Febuary","March","April","May","June",
                   "July","August","September","October","November","December");

foreach($month_array as $month){
    	
echo "<option value='$month'>$month</option>";
}

echo"</select>";

echo"<select name='syear'><option>Year</option>";

$year_array=array("2009","2010","2011","2012","2013","2014","0215");

foreach($year_array as $year){
    	
echo "<option value='$year'>$year</option>";
}

echo"</select></td></tr></table>";

echo"<td>";

//END DATE

echo"<table border='4'><tr><td align='center'>End Date</td></tr>";

echo"<td><select name='eday'><option>Day</option>";

$day_array==range(1,31);

foreach($day_array as $day){
    	
echo "<option value='$day'>$day</option>";
}

echo"</select>";

echo"<select name='emonth'><option>Month</option>";

$month_array=array("January","Febuary","March","April","May","June",
                   "July","August","September","October","November","December");

foreach($month_array as $month){
    	
echo "<option value='$month'>$month</option>";
}

echo"</select>";

echo"<select name='eyear'><option>Year</option>";

$year_array=array("2009","2010","2011","2012","2013","2014","0215");

foreach($year_array as $year){
    	
echo "<option value='$year'>$year</option>";
}

echo"</select></td></tr></table>";
echo"</td>";
echo"</tr></table>";

echo"<br> <input type='submit' name='submit' value='Send!'>";
echo"</td>";
echo"</tr></table>";

echo "</form>";

?>

Link to comment
Share on other sites

I'm unsure as to what you want me to explain - It's a loop and two date/time functions.

 

The loop starts on the start date, and ends on the end date. It adds a day on every iteration of the loop and echos the date at that point. Dates are converted to Unix time stamps, as it's easier to write the code.

Link to comment
Share on other sites

The code was for a doctor, to be able to enter dates she not in, example a holiday ect ect ,

do you think this method is good enough..

 

was going to add all the dates in the database with the doctors id and just match when patients try to book her..

 

any ideas there...

 

This idea good for holiday dates, but no good for single dates, i think ill need a new date picker for entering single dates?

 

any way around it with no ajax/javascript.

Link to comment
Share on other sites

Should enter all info in the database does not?

 

<?php

//database connetion.

if(isset($_POST['submit'])){


$start_date=$_POST['sday'].$_POST['smonth'].$_POST['syear'];

$end_date=$_POST['eday'].$_POST['emonth'].$_POST['eyear'];

for($i=strtotime($start_date); $i<=strtotime($end_date); $i+=86400) {

	$dates=date("d-m-Y",$i);

	$user_id="0001";

	$sql="INSERT INTO important_dates(id,doctor Id,dates,note)VALUES
	('".mysql_real_escape_string($id)."','".mysql_real_escape_string($user_Id)."','".mysql_real_escape_string($dates)."','".mysql_real_escape_string($note)."')";
	$res="mysql_query($sql)or die(mysql_error())";
}

}

?>

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.