robbiez
07-31-2008, 10:30 AM
Hello superheros.
Can you help me with a bit of code please.
I am creating an estimated delivery date script which will echo the date plus 3 days excluding Saturday & Sunday. So far I have this:
<?php echo date('Y-m-d', strtotime("+3 days"));?>
which echos the date plus 3 days - how do I get it excluding Saturday & Sunday in its calculation.
thanks
in advance
Rob
ssonawa
07-31-2008, 10:40 AM
try to put if conditions, getting day numbers using php date function. it may work.
robbiez
07-31-2008, 11:07 AM
I have tried the following but it doesn't work:
<?php
if (date('D') = 'Fri') {$deliverydate = date('Y-m-d', strtotime("+6 days"))};
elseif (date('D') = 'Sat') {$deliverydate = date('Y-m-d', strtotime("+5 days"))};
elseif (date('D') = 'Sun') {$deliverydate = date('Y-m-d', strtotime("+4 days"))};
else $deliverydate = date('Y-m-d', strtotime("+3 days"));
echo $deliverydate ;?>
Am I heading in the right direction??
thanks
robbiez
07-31-2008, 12:33 PM
Hi
I think i got it right by using:
<?php
$today = date('l');
if ($today = 'Thursday') {$deliverydate = date('Y-m-d', strtotime("+5 days"));}
elseif ($today = 'Friday') {$deliverydate = date('Y-m-d', strtotime("+5 days"));}
elseif ($today = 'Saturday') {$deliverydate = date('Y-m-d', strtotime("+4 days"));}
elseif ($today = 'Sunday') {$deliverydate = date('Y-m-d', strtotime("+3 days"));}
else {$deliverydate = date('Y-m-d', strtotime("+3 days"));}
echo $deliverydate ;
?>
thanks for the tips
robbiez
07-31-2008, 12:35 PM
Just a thought..
If the website is UK based & UK hosted do I need the set the time zone to GMT??
If so how??
Thanks
rafiki
07-31-2008, 12:42 PM
http://www.php.net/ini_set
http://www.php.net/manual/en/function.date-default-timezone-set.php
comparisons need ==, = on its own is assignment and will always be true.