## Delivery date

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

mprvijay
New php-forum User
Posts: 2
Joined: Mon Oct 29, 2012 2:06 am

### Delivery date

When the customer order product before Mon 12.00 delivery date should be same week thrusday , if they order after Monday 12.00 the delivery date should be the next week thrusday . Can some help in php code for this problem ..

egami
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

### Re: Delivery date

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: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

### Re: Delivery date

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.

Return to “PHP coding => General”

### Who is online

Users browsing this forum: No registered users and 8 guests