## Delivery date

Moderators: egami, macek, gesf

egami
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT
Days are numbered 0 - 6
Sunday being 0.

Although, recently, you _can_ switch that to Monday = 1 and Sunday = 7.. depends.
php.net/date

So then it becomes a simple math problem.

\$day_no = date('w'); // Sunday = 0;

Now, splitting hairs with time.

Code: Select all

``````if (date('g') >= 12:00) {
\$after12 = TRUE;
}

if (\$day_no >= 1 ) {
if (\$after12) {
// Thursday is 4
// assume today is Tuesday (2)
// (\$day_no - 4) + 6 = 8 days.. Wed,Fri,Sat,Sun,Mon,Tue,Wed,Thur.
\$days = (\$day_no - 4) + 6;
\$next_delivery_day = mktime(0,0,0,date('m'),date('d')+\$days,date('Y'));
} else {
\$days = (\$day_no - 4);
\$next_delivery_day = mktime(0,0,0,date('m'),date('d')+\$days,date('Y'));
}
} else {
\$days = (\$day_no - 4);
\$next_delivery_day = mktime(0,0,0,date('m'),date('d')+\$days,date('Y'));
}
``````

egami
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT
keep in mind, that mktime() delivers the time specified in UNIX time. Seconds since EPOCH.

You can use this number to work with any date function...

\$delivery_date = date('m/d/Y',\$next_delivery_day);

Boom. Done.