Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    strtotime + 3 days excluding weekends.

    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:

    Code:
    <?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

  • #2
    New Coder
    Join Date
    Jul 2008
    Location
    India
    Posts
    39
    Thanks
    0
    Thanked 2 Times in 2 Posts
    try to put if conditions, getting day numbers using php date function. it may work.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I have tried the following but it doesn't work:

    Code:
    <?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
    Last edited by robbiez; 07-31-2008 at 12:11 PM.

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hi

    I think i got it right by using:
    Code:
    <?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

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts

  • #7
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    comparisons need ==, = on its own is assignment and will always be true.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •