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>";

?>

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>";

?>

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.

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.

important dates

 

Id not null auto_increment primary key,

doctor Id int not null,

Date varchar(20) not null,

note text not null

 

each date needs a way to delete also there need to be a note for each date...

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())";
}

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.