View on GitHub

jquery.ofthemonth

A jQuery plugin that returns the js date object of the next specific day (of your choosing) of the month.

Download this project as a .zip file Download this project as a tar.gz file

This plugin is most useful if you are looking to retreive a specific day of the month in the immediate future. For example, let's say you would like to get the JavaScript date object for the "next" Last Friday relatave to today's date. That is exactly what this plugin does. You can get the First, Second, Third, Fourth, Second to Last, or Last upcoming specific weekday, either in the current month or next (depending on what you are looking for).

Usage

  1. Include jQuery and Plugin (assuming your JavaScript is in a folder called 'js')

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/jquery.ofthemonth.js"></script>
    
  2. Call the plugin from your JavaScript

    // default setting will return the last friday
    $(this).ofthemonth();
    
    // but you can change that by adding new defaults, like this
    $.fn.ofthemonth.defaults.whichDay = "Sunday";
    $.fn.ofthemonth.defaults.whichWeek = "first";
    
    // or just set the variables when calling the plugin
    $(this).ofthemonth({whichDay:"Tuesday",whichWeek:"second"}));
    
    // I like to assign this date object to a variable
    var myDate = $(this).ofthemonth();
    

Parameters

The Plugin accepts the following values, which are case sensitive.

whichDay

whichWeek

There you have it, You have a nice and neat date object.

For formatting this date, I really like Moment.js.