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
Related
I need to loop through the days between two dates in intervals of 20 days, including the last date. For example, between the dates 2019/01/01 and 2019/01/27 should return the following ranges:
2019-01-01 => 2019-01-20
2019-01-21 => 2019-02-09
2019-02-10 => 2019-02-27
I have tried with this code:
$start = new DateTime('2019-01-01');
$end = new DateTime('2019-02-27');
$interval = new DateInterval('P20D');
$period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
$from = $start->format('Y-m-d');
foreach ($period as $day) {
$to = $day->format('Y-m-d');
echo $from . ' => ' . $to . '<br>';
$from = $day->modify('+1 day')->format('Y-m-d');
}
Output:
2019-01-01 => 2019-01-21
2019-01-22 => 2019-02-10
This code has two problems, does not include the last period (no longer containing 20 days) and is advanced one day. How can I solve these problems?
This is probably more simply done by just incrementing the $start value by the $interval until it is greater than the $end value. Note that the interval needs to be 19 days to make a 20-day (inclusive of start and end) period.
$start = new DateTime('2019-01-01');
$end = new DateTime('2019-02-27');
$interval = new DateInterval('P19D');
while ($start < $end) {
echo $start->format('Y-m-d') . ' => ';
$start->add($interval);
echo min($start, $end)->format('Y-m-d') . "\n";
$start->add(new DateInterval('P1D'));
}
Output:
2019-01-01 => 2019-01-20
2019-01-21 => 2019-02-09
2019-02-10 => 2019-02-27
Demo on 3v4l.org
Update
Here is a version of the code that also skips weekends:
$start = new DateTime('2019-01-01');
$end = new DateTime('2019-02-27');
$interval = new DateInterval('P1D');
$days = 19;
while ($start < $end) {
echo $start->format('Y-m-d') . ' => ';
for ($i = 0; $i < $days; ) {
$start->add($interval);
$day_of_week = $start->format('N');
if ($day_of_week == 6 || $day_of_week == 7) continue;
$i++;
}
echo min($start, $end)->format('Y-m-d') . "\n";
$start->add($interval);
}
Demo on 3v4l.org
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 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
I'm trying to create an array of the next 5 working week days (Monday - Friday, excluding today). I know the working week varies around the world but this is not important for what I am trying to do.
So, for example, if today is a Wednesday, I want the dates for Thursday and Friday of the current week and Monday, Tuesday and Wednesday of the following week.
I thought this would work:
$dates = array();
for ($i = 1; $ < 6; $i ++)
{
$dates[] = date('Y-m-d', strtotime('+ '.$i.' weekday'));
}
But for today, it is giving me:
Monday 1st
Tuesday 2nd
Wednesday 3rd
Thursday 4th
Sunday 7th!
Any advice appreciated.
Thanks
Try this
$dates = array();
$date = new DateTime();
while (count($dates)<5)
{
$date->add(new DateInterval('P1D'));
if ($date->format('N')<6)
$dates[]=$date->format('Y-m-d');
}
function getWeekdayDatesFrom($format, $start_date_epoch, $end_date_epoch, $range) {
$dates_arr = array();
if( ! $range) {
$range = round(abs($start_date_epoch-$end_date_epoch)/86400) + 1;
} else {
$range = $range + 1; //end date inclusive
}
$current_date_epoch = $start_date_epoch;
for($i = 1; $i <= $range; $i+1) {
$d = date('N', $current_date_epoch);
if($d <= 5) { // not sat or sun
$dates_arr[] = "'".date($format, $current_date_epoch)."'";
}
$next_day_epoch = strtotime('+'.$i.'day', $start_date_epoch);
$i++;
$current_date_epoch = $next_day_epoch;
}
return $dates_arr;
}
This should work:
$dates = array();
$i = 0;
while(true) {
$i++;
$time = strtotime("+$i days");
$dayOfWeek = date('w', $time);
/* 'w' - day of week, numeric, i.e. "0" (Sunday) to "6" (Saturday) */
if( ($dayOfWeek == 0) or ($dayOfWeek == 6) ) {
continue;
}
$dates[] = date('Y-m-d', $time);
if( count($dates) >= 5 ) {
break;
}
}
You can do like this:
$now = time();
$day = 60*60*24;
$days = array();
for ($i=1; $i<=7; $i++){
$ts = $now + $day*$i;
if (date("N", $ts) < 6){
$days[] = date("l jS", $ts);
}
}
The output for the above code is:
Array(
[0] => Monday 1st
[1] => Tuesday 2nd
[2] => Wednesday 3rd
[3] => Thursday 4th
[4] => Friday 5th
)