# date() question

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

Hello all.

Is there an easy way to populate this array with only the working days (no
Sat or Sun) from the last 60 days.

for(\$i = 1; \$i <= 60; \$i++) {

\$pastDates = date("Y-m-d", mktime(0, 0, 0, date("m")-2, date("d")+\$i,
date("Y")));

\$findPastDates = array(\$pastDates);

}

## Re: date() question

With something like strtotime("now -60 day"); the answer is near ;p

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info

## Re: date() question

ZMAN wrote:

You can always do it like this, which saves all the calls to date() in
the loop:

\$day = date('d');
\$month = date('m');
\$year = date('Y');
\$dates = array();

for(\$i = -59; \$i < 1; \$i++) {
\$dates[] = date('Y-m-d', mktime(0, 0, 0, \$month, \$day+\$i, \$year));
}

This gives you an array like so:

[0] => 2004-11-23
[1] => 2004-11-24
[2] => 2004-11-25
[3] => 2004-11-26
....

Although we're making the day passed to mktime() negative it correctly
works out the month and year.

If you wanted to not include sat or sun you could modify it like so:

for(\$i = -59; \$i < 1; \$i++) {
\$timestamp = mktime(0, 0, 0, \$month, \$day+\$i, \$year);
\$day_of_week = date('w', \$timestamp);
if(\$day_of_week != 0 && \$day_of_week != 6) {
\$dates[] = date('Y-m-d', \$timestamp);
}
}

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com /