Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 29, 2013 10:14
Show Gist options
  • Save phpfiddle/6376402 to your computer and use it in GitHub Desktop.
Save phpfiddle/6376402 to your computer and use it in GitHub Desktop.
datetodateMCA140
<?php
function getDates($from_date, $to_date){
$start = strtotime($from_date);
$end = strtotime($to_date);
$days = $end - $start;
$days = ceil($days/86400);
// echo $days;
$n=0;
$weekdays=array("MONDAY","TUESDAY","WEDNESDAY", "THURDAY", "FRIDAY", "SATURDAY","SUNDAY" );
$weekdays1=array("MON","TUE","WED", "THU", "FRI", "SAT","SUN" );
$dt = strtotime($from_date);
$day = date("D", $dt);
$day1= strtoupper($day);
$date = $from_date;
$date1 = date('Y-m-d', strtotime("-1 day $date"));
for ($i = 0; $i <= 6; $i++)
{
if($weekdays1[$i]==$day1)
{
while($n<$days)
{
echo $weekdays[$i];
echo " - ";
$date_next2 = date('d-m-Y', strtotime("+1 day $date1"));
echo $date_next2;
$date1= $date_next2;
$i++;
if($i==6)
$i=0;
$n++;
echo " ";
}
}
}
// Implement the logic for listing the Days from given range of dates and also prints the day of the date
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if(isset($_POST['from_date']) && isset($_POST['to_date'])){
extract($_POST);
$dates = getDates($from_date,$to_date);
?>
<table>
<tr><th>Date</th><th>Day</th></tr>
<?php
// Display the Dates with day here
?>
</table>
<?php
} else{
?>
<h3>My form</h3>
<form method="post">
<label>From (mm/dd/yyyy)</label> <input type="text" value="<?php echo date('m/d/Y');?>" size="30" maxlength="100" placeholder="mm/dd/yyyy" name="from_date" /><br />
<label>To(mm/dd/yyyy)</label> <input type="text" value="<?php echo date('m/d/Y',strtotime('+1 day',time()));?>" size="30" maxlength="100" placeholder="mm/dd/yyyy" name="to_date" /><br />
<button id="mysubmit" type="submit">Submit</button><br /><br />
</form>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment