…meie igapäevast IT’d anna meile igapäev…

2010-08-23

JavaScript dates: current quarter, previous quarter

Filed under: JavaScript — Sander @ 12:09:36
Tags: , ,
function dateRangeClick(id) {	
  var d = new Date();
  var quarter = Math.floor((d.getMonth() / 3));	
  
  switch (id) {
    case "CurrentQuarter":      
      var firstDate = new Date(d.getFullYear(), quarter * 3, 1);
      $("#startDate").datepicker("setDate", firstDate);
      $("#endDate").datepicker("setDate", new Date(firstDate.getFullYear(), firstDate.getMonth() + 3, 0));
    break;
    case "PreviousQuarter":
      var firstDate = new Date(d.getFullYear(), quarter * 3 - 3, 1);
      $("#startDate").datepicker("setDate", firstDate);
$("#endDate").datepicker("setDate", new Date(firstDate.getFullYear(), firstDate.getMonth() + 3, 0));
    break;
   }
}

See also:  JavaScript dates: get Monday, get Sunday, get last day of a month

Lisa kommentaar »

Kommentaare veel pole.

RSS feed for comments on this post. TrackBack URI

Lisa kommentaar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Muuda )

Twitter picture

You are commenting using your Twitter account. Log Out / Muuda )

Facebook photo

You are commenting using your Facebook account. Log Out / Muuda )

Google+ photo

You are commenting using your Google+ account. Log Out / Muuda )

Connecting to %s

Blog at WordPress.com.