Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 29, 2013 09:52
Show Gist options
  • Save phpfiddle/6376223 to your computer and use it in GitHub Desktop.
Save phpfiddle/6376223 to your computer and use it in GitHub Desktop.
date2dayMCA140
<?php
function getDates($from_date, $to_date){
$i=0;
if(!$from_date || !$to_date ) {return false;}
$dateMonthYearArr = array();
$fromDate = strtotime($from_date);
$toDate = strtotime($to_date);
for ($currentDate = $fromDate; $currentDate <= $toDate; $currentDate += (60 * 60 * 24))
{
$currentDateStr = date("m/d/Y",$currentDate);
$dateMonthYearArr[] = $currentDateStr;
$i++;
}
return $dateMonthYearArr;
// 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