www.webdeveloper.com
Results 1 to 3 of 3

Thread: Finding last but one friday of current month

  1. #1
    Join Date
    May 2014
    Posts
    1

    Finding last but one friday of current month

    Hi Team,
    Can you suggest the best way to find the last but one friday of each month.
    thanks in advance

  2. #2
    Join Date
    Mar 2011
    Posts
    61
    Not sure if it's the best way. But it works.
    Code:
    var year = 2014;
    
    for(var month=0; month<12; month++){
     var lastDay		= new Date(y, month+1, 0);
     var lastFriday 	= new Date(2014, month+1, -((lastDay.getDay()+2) %7));
     var lastButOneFriday	= new Date(2014, month+1, -(7+(lastDay.getDay()+2) %7));
     document.write(lastButOneFriday.toDateString()+'<br>')
    }

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,380

    Lightbulb

    Alternative function...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> HTML5 page </title>
    
    </head>
    <body>
    
    <script type="text/javascript">
    function checkForLastFridays(fricnt) {
      var d = new Date();
      d.setFullYear(d.getFullYear(), d.getMonth(), 0);
      do {
        d.setFullYear(d.getFullYear(), d.getMonth(), d.getDate()-1);
        if (d.getDay() == 5) { fricnt--; }
      } while (fricnt != 0);  
      return d.toDateString();
    }
    
    // example
    alert('Last Friday: '+checkForLastFridays(1));
    alert('2nd to last Friday: '+checkForLastFridays(2));
    </script>
    
    </body>
    </html>
    Last edited by JMRKER; 05-19-2014 at 10:14 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles