CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2005
    Posts
    135

    find 6th working day

    Any ideas on how I can find the 6th working day of each month?
    I don't want to put in a check for if Monday, else if Tuesday advance 1 day, etc. although maybe this is the only way?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: find 6th working day

    In what language are you planning to implement this? If PHP, you can easily do this using date() and mktime().

    Pay good attention to example #1 (4th implementation) of the date() page.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2005
    Posts
    135

    Re: find 6th working day

    Yes, but date() doesn't have a built in check for working days.
    I assume I am going to have to code and check the actual day:
    if day == 6 and saturday or sunday then day++
    then do a recursive loop until it equals monday-Friday?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: find 6th working day

    EDIT: Ah, only Mon-Fri. You will have to do an if statement for that.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: find 6th working day

    Here is a quick implementation I just wrote up. This should work for you.

    PHP Code:
    <?php
    function sixthDay($m$y) {
      
    $n 0;
      for (
    $d 1$d <= date('t'mktime(000$m1$y)); $d++) {
        
    $tempDate date('l'mktime(000$m$d$y));
        if (
    $tempDate !== 'Saturday' && $tempDate !== 'Sunday') {$n++;}
        if (
    $n == 6) {break;}
      }
      return 
    $tempDate;
    }

    echo 
    sixthDay(62008);
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Nov 2005
    Posts
    135

    Cool Re: find 6th working day

    Example #1 doesn't have any working day code in it ?
    There is some working day code further down but only to find the number of working days in a month, which is a calculation...

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: find 6th working day

    We posted at the same time. Read my last post.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Nov 2005
    Posts
    135

    Re: find 6th working day

    Perfect. Thanks very much.
    I'll make some slight alterations to get the day numbers...

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured