var format = d3.time.format("%d %b %Y");
//format.parse("2011-01-01"); // returns a Date
var result = format(new Date()); // returns a string
function daysLeftInQuarter(d) {
d = d || new Date();
var qEnd = new Date(d);
qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);
return Math.floor((qEnd - d) / 8.64e7);
}
//d3.select("body").append("div").html(daysLeftInQuarter());
var today = new Date();
var month = today.getMonth() + 1;
var qtrMonth = (month <= 3) ? 3 : (month <= 6) ? 6 : (month <= 9) ? 9 : 12;
var qtrLastDay = (qtrMonth == 3 || qtrMonth == 12) ? 31 : 30;
var qtrDate = new Date(Date.parse(qtrMonth + "/" + qtrLastDay + "/" + today.getFullYear()));
//get the difference between the 2 dates in milliseconds
var dateDiff = qtrDate.getTime() - today.getTime();
//convert the dateDiff to days and round up to the nearest day (rounding up ensures that the time that has elapsed in the current day is still counted)
dateDiff = Math.ceil(dateDiff / 1000 / 60 / 60 / 24);
// display day left
//document.write(dateDiff + " days until quarter end on " + qtrDate);
d3.select("body").append("div").html(dateDiff);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.