Delivery date

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Re: Delivery date

Post by egami » Fri Nov 02, 2012 9:49 am

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'));
}
 

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

Re: Delivery date

Post by egami » Fri Nov 02, 2012 9:50 am

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests