I want to split the current month in to weeks like first day to saturday and then sunday to next saturday.For ex: for May month, So i want to split that like
2016-05-01 to 2016-05-07
2016-05-08 to 2016-05-14
2016-05-15 to 2016-05-21
2016-05-22 to 2016-05-28
2016-05-29 to 2016-05-31
if i try the below code,i didnt get exact result.
<?php
$start_date = date('Y-m-d', strtotime('2016-06-01'));
$end_date = date('Y-m-d', strtotime('2016-06-30'));
$i=1;
for($date = $start_date; $date <= $end_date; $date = date('Y-m-d', strtotime($date. ' + 7 days'))) {
echo getWeekDates($date, $start_date, $end_date, $i);
echo "\n";
$i++;
}
function getWeekDates($date, $start_date, $end_date, $i) {
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("{$year}-W{$week}+1"));
if($from < $start_date) $from = $start_date;
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7"));
if($to > $end_date) $to = $end_date;
echo $from." - ".$to.'<br>';
}
?>
i got like
2016-05-01 - 2016-05-01
2016-05-01 - 2016-05-08
2016-05-08 - 2016-05-15
2016-05-15 - 2016-05-22
2016-05-22 - 2016-05-29
In for loop, while checking last set of days, conditon get failed .so it doesnt calculate 30,31.
How can i do that?
DateTime, DatePeriod and DateInterval are your friends to do that quickly!
See online.
<?php
/**
* #file
* Awnser to http://stackoverflow.com/q/37224961/392725
*
* #link http://stackoverflow.com/a/37228497/392725
*/
date_default_timezone_set('Europe/Paris');
function getWeekDates(DateTimeInterface $date, $format = 'Y-m-d') {
$dt = \DateTimeImmutable::createFromMutable($date);
$first_day = $dt->modify('first day of this month');
$last_day = $dt->modify('last day of this month');
$period = new \DatePeriod(
$first_day,
\DateInterval::createFromDateString('sunday this week'),
$last_day,
\DatePeriod::EXCLUDE_START_DATE
);
$weeks = [$first_day->format($format)];
foreach ($period as $d) {
$weeks[] = $d->modify('-1 day')->format($format);
$weeks[] = $d->format($format);
}
$weeks[] = $last_day->format($format);
return array_chunk($weeks, 2);
}
echo "Weeks of the current month:\n";
$weeks = getWeekDates(new \DateTime('now'));
array_walk($weeks, function ($week) {
vprintf("%s to %s\n", $week);
});
echo "\nWeeks of the month may 2016:\n";
$weeks = getWeekDates(new \DateTime('2016-05'));
array_walk($weeks, function ($week) {
vprintf("%s to %s\n", $week);
});
echo "\nWeeks of the month june 2016:\n";
$weeks = getWeekDates(new \DateTime('2016-06'));
array_walk($weeks, function ($week) {
vprintf("%s to %s\n", $week);
});
echo "\nWeeks of the month october 2016:\n";
$weeks = getWeekDates(new \DateTime('2016-10'));
array_walk($weeks, function ($week) {
vprintf("%s to %s\n", $week);
});
Result:
Weeks of the current month:
2016-05-01 to 2016-05-07
2016-05-08 to 2016-05-14
2016-05-15 to 2016-05-21
2016-05-22 to 2016-05-28
2016-05-29 to 2016-05-31
Weeks of the month may 2016:
2016-05-01 to 2016-05-07
2016-05-08 to 2016-05-14
2016-05-15 to 2016-05-21
2016-05-22 to 2016-05-28
2016-05-29 to 2016-05-31
Weeks of the month june 2016:
2016-06-01 to 2016-06-04
2016-06-05 to 2016-06-11
2016-06-12 to 2016-06-18
2016-06-19 to 2016-06-25
2016-06-26 to 2016-06-30
Weeks of the month october 2016:
2016-10-01 to 2016-10-01
2016-10-02 to 2016-10-08
2016-10-09 to 2016-10-15
2016-10-16 to 2016-10-22
2016-10-23 to 2016-10-29
2016-10-30 to 2016-10-31
Try like this, I assume you can change month variable according to your need.
$month=5;//pass here your month
$first_date = date("Y-m-1");
do{
$last_date = date("Y-m-d",strtotime($first_date. " +6 days"));
$month = date("m",strtotime($last_date));
if($month!=5)
$last_date = date("Y-m-t");
echo "<br>".$first_date." - ".$last_date;
$first_date = date("Y-m-d",strtotime($last_date. " +1 days"));
}while($month == 5);
Check here : https://eval.in/571521
Modified Rishi's code, fixed some problem places and solved the problem of leap years when splitting February into weeks:
$weeks = monthToWeeks(2016, '02');
print_r($weeks);
function monthToWeeks($y, $m)
{
$weeks = [];
$month = $m;
$first_date = date("{$y}-{$m}-01");
do {
$last_date = date("Y-m-d", strtotime($first_date. " +6 days"));
$month = date("m", strtotime($last_date));
if ($month != $m) {
$last_date = date("Y-m-t", mktime(0, 0, 0, $m, 1, $y));
if ($first_date > $last_date) {
break;
}
}
$weeks[] = [$first_date, $last_date];
$first_date = date("Y-m-d", strtotime($last_date. " +1 days"));
} while($month == intval($m));
return $weeks;
}
You may try it here https://eval.in/643724
function getSaturdays($y, $m)
{
return new DatePeriod(
new DateTime("first saturday of $y-$m"),
DateInterval::createFromDateString('next saturday'),
new DateTime("last day of $y-$m")
);
}
function list_week_days($year, $month) {
$first_month_day = new DateTime("first day of $year-$month") ;
echo $first_month_day->format("Y-m-d\n") . '-';
foreach (getSaturdays($year, $month) as $saturday) {
echo $saturday->format(" Y-m-d\n");
echo '-<br>';
$sunday = $saturday->modify('next Sunday');
echo $sunday->format(" Y-m-d\n");
}
$last_month_day = new DateTime("last day of $year-$month");
echo $last_month_day->format("Y-m-d\n");
}
list_week_days(2016, 5);
p.s.
I encorege you to use DateTime class
Related
Hello guys i am working in php and my requirement is to get complete week dates from given date as i need to calculate weekly working hour. And week must be started from sunday to saturday not monday to sunday. I have code which works properly for other days of week except sunday. it means if give any dates from monday to saturday it works properly but if i give sunday's date it give last week's dates. please check my code and advise me for better solution.
$days = array();
$ddate = "2018-01-07";
$date = new DateTime($ddate);
$week = $date->format("W");
$y = date("Y", strtotime($ddate));
echo "Weeknummer: $week"."<br>";
echo "Year: $y"."<br>";
for($day=0; $day<=6; $day++)
{
$days[$day] = date('Y-m-d', strtotime($y."W".$week.$day))."<br>";
}
print_r($days);
Using the DateTime, DateInterval and DatePeriod classes you could do it like this perhaps
function getperiod( $start ){
return new DatePeriod(
new DateTime( $start ),
new DateInterval('P1D'),
new DateTime( date( DATE_COOKIE, strtotime( $start . '+ 7days' ) ) )
);
}
$start='2018-01-07';
$period=getperiod( $start );
foreach( $period as $date ){
echo $date->format('l -> Y-m-d') . '<br />';
}
Which returns
Sunday -> 2018-01-07
Monday -> 2018-01-08
Tuesday -> 2018-01-09
Wednesday -> 2018-01-10
Thursday -> 2018-01-11
Friday -> 2018-01-12
Saturday -> 2018-01-13
Or, by modifying the parameters of the getperiod function you can make that function far more flexible.
function getperiod( $start, $interval='P1D', $days=7 ){
return new DatePeriod(
new DateTime( $start ),
new DateInterval( $interval ),
new DateTime( date( DATE_COOKIE, strtotime( $start . '+ '.$days.' days' ) ) )
);
}
$start='2018-01-07';
$days=array();
$period=getperiod( $start );
foreach( $period as $date ){
$days[]=$date->format('Y-m-d');
}
echo '<pre>',print_r($days,true),'</pre>';
For instance: To find every Sunday for the next year
$period=getperiod( $start,'P7D', 365 );
foreach( $period as $date ){
$days[]=$date->format('Y-m-d');
}
echo '<pre>',print_r($days,true),'</pre>';
To ensure that the calculations begin on a Sunday which has a numeric value of 7
function getperiod( $start, $interval='P1D', $days=7 ){
return new DatePeriod(
new DateTime( $start ),
new DateInterval( $interval ),
new DateTime( date( DATE_COOKIE, strtotime( $start . '+ '.$days.' days' ) ) )
);
}
/* A date from which to begin calculations */
$start='2018-01-01';
/* Array to store output */
$days=array();
/* integer to represent which day of the week to operate upon */
$startday = 7;
/* Output format for resultant dates */
$output='Y-m-d';
/* Calculate initial startdate given above variables */
$start=date( DATE_COOKIE, strtotime( $start . ' + ' . ( $startday - date( 'N', strtotime( $start ) ) ) . ' days' ) );
/* Get the period range */
$period=getperiod( $start );
foreach( $period as $date ){
/* store output in desired format */
$days[]=$date->format( $output );
}
/* do something with data */
echo '<pre>',print_r($days,true),'</pre>';
From source,
Here is the snippet you are looking for,
// set current date
$date = '01/03/2018';
// parse about any English textual datetime description into a Unix timestamp
$ts = strtotime($date);
// calculate the number of days since Monday
$dow = date('w', $ts);
$offset = $dow - 1;
if ($offset < 0) {
$offset = 6;
}
// calculate timestamp for the Monday
$ts = $ts - $offset*86400;
// loop from Monday till Sunday
for ($i = 0; $i < 7; $i++, $ts += 86400){
print date("m/d/Y l", $ts) . "\n";
}
Here is working demo.
If you need normal standard format code,
Here is your snippet,
// set current date
$date = '2018-01-03';
// parse about any English textual datetime description into a Unix timestamp
$ts = strtotime($date);
// calculate the number of days since Monday
$dow = date('w', $ts);
$offset = $dow - 1;
if ($offset < 0) {
$offset = 6;
}
// calculate timestamp for the Monday
$ts = $ts - $offset * 86400;
// loop from Monday till Sunday
for ($i = 0; $i < 7; $i++, $ts += 86400) {
print date("Y-m-d l", $ts) . "\n";
}
Here is working demo.
EDIT
As per your requirement, now week will start from sunday to saturday
<?php
// set current date
$date = '2018-01-03';
// parse about any English textual datetime description into a Unix timestamp
$ts = strtotime($date);
// calculate the number of days since Sunday
$dow = date('w', $ts);
$offset = $dow;
if ($offset < 0) {
$offset = 6;
}
// calculate timestamp for the Sunday
$ts = $ts - $offset * 86400;
// loop from Sunday till Saturday
for ($i = 0; $i < 7; $i++, $ts += 86400) {
print date("Y-m-d l", $ts) . "\n";
}
<?php
$days = array();
$ddate = "2018-01-07";
$y = date("Y", strtotime($ddate));
if(date("l", strtotime($ddate))=='Sunday'){
$ddate = date("Y-m-d ", strtotime($ddate. "+1 day"));
}
$date = new DateTime($ddate);
$week = $date->format("W");
echo "<br/>";
echo "Weeknummer: $week"."<br>";
echo "Year: $y"."<br>";
for($day=0; $day<=6; $day++)
{
$days[$day] = date('Y-m-d', strtotime($y."W".$week.$day))."<br>";
}
print_r($days);
?>
try this:
$days = array();
$ddate = "2018-01-07";
$date = new DateTime($ddate);
$week = $date->format("N")==7?$date->modify("+1 week")->format("W"):$date->format("W");
$y = date("Y", strtotime($ddate));
echo "Weeknummer: $week"."<br>";
echo "Year: $y"."<br>";
for($day=0; $day<=6; $day++)
{
$days[$day] = date('Y-m-d', strtotime($y."W".$week.$day))."<br>";
}
print_r($days);
$dto = new DateTime();
$year = date_create($this->week_date)->format('o');
$week_no = date('W', strtotime($this->week_date));
$dto->setISODate($year, $week_no);
$dto->modify('-1 days');
$ret['sunday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['monday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['tuesday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['wednesday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['thursday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['friday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['saturday'] = $dto->format('Y-m-d');
$dto->modify('+1 days');
$ret['next_sunday'] = $dto->format('Y-m-d');
I have this form with this input field
<input type="text" name="txt_datetimein" class="form-control datetime">
<input type="text" name="txt_datetimeout" class="form-control datetime">
<input type="text" name="txt_lenght" class="form-control">
I enter the first date and the second date and the length the length i precise the number of repetition
than i click next and i have all days without sunday
example if i put 5 in the length and datetimein 01-04-2017 8:00:00 and datetimeout is 01-04-2017 5:00:00
the output will be like that
Date IN Date Out Day
01-04-2017 8:00:00 01-04-2017 5:00:00 Saturday
03-04-2017 8:00:00 03-04-2017 5:00:00 Monday
04-04-2017 8:00:00 04-04-2017 5:00:00 Tuesday
05-04-2017 8:00:00 05-04-2017 5:00:00 Wednesday
06-04-2017 8:00:00 06-04-2017 5:00:00 Thursday
07-04-2017 8:00:00 07-04-2017 5:00:00 Friday
this my code but it's print all day
<?php
for($i=0;$i<=$lenght;$i++) {
$date = date('m/d/Y H:i:s', strtotime("+$i days", strtotime($datetimein)));
$edate = date('m/d/Y H:i:s', strtotime("+$i days", strtotime( $datetimeout)));
$is_sunday = date('l', strtotime($date)) == 'Sunday';
if ($is_sunday) {
$day = date('l', strtotime("+1+$i days",strtotime($datetimein)));
}
else {
$day = date('l', strtotime("+$i days",strtotime($datetimein)));
}
}
?>
How Can i solve my Problem ??!!
try this below code
$datetimein = "01-04-2017 8:00:00";
$datetimeout = "01-04-2017 5:00:00";
$lenght = 20;
for($i=0;$i<=$lenght;$i++) {
$date = date('m/d/Y H:i:s', strtotime("+$i days", strtotime($datetimein)));
$edate = date('m/d/Y H:i:s', strtotime("+$i days", strtotime( $datetimeout)));
$is_sunday = date('l', strtotime($date));
if($is_sunday == "Sunday")
{
$i=$i+1;
}
$day = date('l', strtotime("$i days",strtotime($datetimein)));
echo $day."<br>";
}
Use DateTime and all those objects. Simpler and cleaner :-)
<?php
$begin = new DateTime();
$end = clone $begin;
$end = $end->modify('+14 day');
$interval = new DateInterval('P1D');
$range = new DatePeriod($begin, $interval ,$end);
foreach($range as $date) {
if ($date->format('N') !== 7) {
echo $date->format('Y-m-d'), '<br>';
}
}
Date format N is the day of week as a number where 7 === Sunday.
Here is you programe
$datetimein = '01-04-2017 8:00:00';
$datetimeout= '01-04-2017 5:00:00';
$lenght = 5;
$i=0;
$days = array();
$dt = strtotime($datetimein);
while($i < $lenght){
if(date('D',$dt)!='Sun'){
$days[] = date('Y-m-d D',$dt);
$i++;
}
$dt = $dt+24*3600;
}
print_r($days);
In this line $days[] = date('Y-m-d D',$dt); change the format or save both in and out time whatever you want. $days will have you expected dates.
It looks like you have mis-spelled the variable length.
Check this.
<?php
$lenght = 5;
$in_temp = 0;
$out_temp = 0;
for($i=0;$i<=$lenght;$i++) {
$in = strtotime($datetimein) + $in_temp;
$out = strtotime($datetimeout) + $out_temp;
$date = date('m/d/Y H:i:s', strtotime("+$i days", $in));
$edate = date('m/d/Y H:i:s', strtotime("+$i days", $out));
$is_sunday = strtolower(date('l', strtotime($date))) == 'sunday';
if ($is_sunday) {
$in_temp += 86400 ; // Adding 1 day in seconds.
$day = date('l', (strtotime($date)+$in_temp));
}
else {
$day = date('l', (strtotime($date)));
}
echo $day."\n";
}
?>
I want to update my date every wednesday at 12:00 A.M. in the dropdown in php and remains unchanged till next wednesday.
Following is my code:
$now = time(); // current timestamp
$today = date("w", $now); // "w" returns the weekday (number)
$wednesday = 3; // 5th day of the week (sunday = 0)
if ($today == $wednesday) {
$ts = $now; // today is wednesday, don't change the timestamp
$daysLeft = 0; // no days left!
} else {
$daysLeft = $wednesday-$today; // get the left days
$ts = $now + 84600 * $daysLeft; // now + seconds of one day * days left
}
?>
<h1>
Forecast for <?php echo date("Y-m-d", $ts) ?>
</h1>
In it date remains unchanged on wednesday which is correct and then change quickly as soon as thursday begins. Although I want it to remain same till next wednesday.
I think you are over-complicating the issue.
<?php
$today = time();
$nextWed = strtotime('next wednesday');
if(date('D', $today) === 'Wed') {
$ts = date('Y-m-d', $today);
} else {
$ts = date('Y-m-d', $nextWed);
}
echo '<h1>Forecast for '.$ts.'</h1>';
?>
What's happening?
Get timestamp for today
Get timestamp for next Wednesday
If today is Wednesday, $ts = today's date
If today is NOT Wednesday, $ts = next Wednesday's date
Echo your results
EDIT
<?php
$now = time();
$today = date('Y-m-d', $now);
if(date('D', $now) === 'Wed') { $nextWed = strtotime($today); }
if(date('D', $now) === 'Thu') { $nextWed = strtotime("$today - 1 days"); }
if(date('D', $now) === 'Fri') { $nextWed = strtotime("$today - 2 days"); }
if(date('D', $now) === 'Sat') { $nextWed = strtotime("$today - 3 days"); }
if(date('D', $now) === 'Sun') { $nextWed = strtotime("$today - 4 days"); }
if(date('D', $now) === 'Mon') { $nextWed = strtotime("$today - 5 days"); }
if(date('D', $now) === 'Tue') { $nextWed = strtotime("$today - 6 days"); }
$ts = date('Y-m-d', $nextWed);
echo '<h1>Forecast for '.$ts.'</h1>'
?>
I have date ranges called from and to.I want to convert it to weeks.
Suppose from date is 1-10-2014 and to date is 31-10-2014
Then result is:
1st week : 01-10-2014 to 04-10-2014
2nd : 05-102014 to 11-10-2014
3rd : 12-10-2014 to 18-10-2014
4th : 19-10-2014 to 25-10-2014
5th : 26-10-2014 to 31-10-2014
In php.I try several code but that didn't given the absolute result only give 01 to 7 , 8 to 14 etc.
Pls help.
I already try answers from
Get the date of one week from today with PHP in stack overflow
date("Y-m-d",strtotime("+1 week"));
This snippet uses Sunday as the first day of the week:
$start = new DateTime('2014-10-01');
$end = new DateTime('2014-10-31 23:59');
$interval = new DateInterval('P1D');
$dateRange = new DatePeriod($start, $interval, $end);
$weekNumber = 1;
$weeks = array();
foreach ($dateRange as $date) {
$weeks[$weekNumber][] = $date->format('Y-m-d');
if ($date->format('w') == 6) {
$weekNumber++;
}
}
Each week will have all the days in it.
If you just want the first and last days of each week then you can just use array_shift and array_pop to get them. For example, for the first week you can use:
$wk1Start = array_shift($weeks[1]); //gives you first day of week 1
$wk1End = array_pop($weeks[1]); // give you the last day of week 1
If you want the start and end dates for each week, here is a way of doing it:
$ranges = array_map(function($week) {
return 'start: ' . array_shift($week)
. ', end: ' . array_pop($week); },
$weeks);
This is the output of $ranges for me:
Array
(
[1] => start: 2014-10-01, end: 2014-10-04
[2] => start: 2014-10-05, end: 2014-10-11
[3] => start: 2014-10-12, end: 2014-10-18
[4] => start: 2014-10-19, end: 2014-10-25
[5] => start: 2014-10-26, end: 2014-10-31
)
You can easily change the week starting day (set to Monday at the moment):
$fromDate = '2018-05-03';
$toDate = '2018-08-11';
$result = getWeekRanges($fromDate, $toDate);
array_walk_recursive($result, 'applyFormat');
echo '<pre>';
print_r($result);
echo '</pre>';
function getWeekRanges($start, $end) {
$timeStart = strtotime($start);
$timeEnd = strtotime($end);
$out = [];
$milestones[] = $timeStart;
$timeEndWeek = strtotime('next Monday', $timeStart);
while ($timeEndWeek < $timeEnd) {
$milestones[] = $timeEndWeek;
$timeEndWeek = strtotime('+1 week', $timeEndWeek);
}
$milestones[] = $timeEnd;
$count = count($milestones);
for ($i = 1; $i < $count; $i++) {
if( $i == $count - 1) {
$out[] = [
'start' => $milestones[$i - 1],
'end' => $milestones[$i]
];
}else{
$out[] = [
'start' => $milestones[$i - 1],
'end' => $milestones[$i] - 1
];
}
}
return $out;
}
function applyFormat(&$item) {
$item = date('Y-m-d', $item);
}
Try
$start_date = date('Y-m-d', strtotime('2014-10-01'));
$end_date = date('Y-m-d', strtotime('2014-10-31'));
$i=1;
for($date = $start_date; $date <= $end_date; $date = date('Y-m-d', strtotime($date. ' + 7 days'))) {
echo getWeekDates($date, $start_date, $end_date, $i);
echo "\n";
$i++;
}
function getWeekDates($date, $start_date, $end_date, $i) {
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("{$year}-W{$week}+1")); //Returns the date of monday in week
if($from < $start_date) $from = $start_date;
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7")); //Returns the date of sunday in week
if($to > $end_date) $to = $end_date;
echo "$i th ".$from." to ".$to.'<br>';
}
output :-
1 th 2014-10-01 to 2014-10-05
2 th 2014-10-06 to 2014-10-12
3 th 2014-10-13 to 2014-10-19
4 th 2014-10-20 to 2014-10-26
5 th 2014-10-27 to 2014-10-31
This question already has answers here:
PHP: Return all dates between two dates in an array [duplicate]
(26 answers)
Closed 4 years ago.
<?php
$start=date('2013-05-02');
$end=date('2013-05-06');
?>
I got out put like following,I don't know how to get this please help me
Thursday 2013-05-02
Friday 2013-05-03
Saturday 2013-05-04
Sunday 2013-05-05
Monday 2013-05-06
$start = new DateTime('2013-5-02');
$end = new DateTime('2013-6-02');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $dt)
{
echo $dt->format("l Y-m-d");
echo "<br>";
}
Note[it's support only Above 5.3.0 php version]
Adapting the answer found here you can quite easily do this.
function createDateRangeArray($strDateFrom,$strDateTo)
{
// takes two dates formatted as YYYY-MM-DD and creates an
// inclusive array of the dates between the from and to dates.
// could test validity of dates here but I'm already doing
// that in the main script
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('l Y-m-d',$iDateFrom));
}
}
return $aryRange;
}
$start=date('2013-05-02');
$end=date('2013-05-06');
echo '<pre>'.print_r(createDateRangeArray($start, $end), 1).'</pre>';
This will work for you
<?php
function dateRange($start, $end) {
date_default_timezone_set('UTC');
$diff = strtotime($end) - strtotime($start);
$daysBetween = floor($diff/(60*60*24));
$formattedDates = array();
for ($i = 0; $i <= $daysBetween; $i++) {
$tmpDate = date('Y-m-d', strtotime($start . " + $i days"));
$formattedDates[] = date('l Y-m-d', strtotime($tmpDate));
}
return $formattedDates;
}
$start='2013-05-02';
$end='2013-05-06';
$formattedDates = dateRange($start, $end);
echo join(', ', $formattedDates);
// => Thursday 2013-05-02, Friday 2013-05-03, Saturday 2013-05-04, Sunday 2013-05-05, Monday 2013-05-06
Check this out,
<?php
$from_date = strtotime("2013-05-02");
$to_date = strtotime("2013-08-02");
for ($current_date = $from_date; $current_date <= $to_date; $current_date += (60 * 60 * 24)) { // looping for avvailable dates
// use date() and $currentDateTS to format the dates in between
$date = date("Y-m-d",$current_date);
$day_name = getdate($current_date) ;
$day_name = $day_name['weekday'];
echo $date." ".$day_name."<br>";
}
?>