Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Delivery date

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Delivery date

Postby mprvijay » Fri Nov 02, 2012 3:54 am

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 ..
mprvijay
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Oct 29, 2012 2:06 am

Re: Delivery date

Postby 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 >= ) { 
  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

Postby 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.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron