Another fast snippet: how to group by the date.day from a date/datetime column.
select sum(amount) as total, dateadd(DAY,0, datediff(day,0, created)) as created from sales group by dateadd(DAY,0, datediff(day,0, created))
Another fast snippet: how to group by the date.day from a date/datetime column.
select sum(amount) as total, dateadd(DAY,0, datediff(day,0, created)) as created from sales group by dateadd(DAY,0, datediff(day,0, created))
Here two simple snippets useful to add (or subtract) months to a Date object:
function add_months(dt, n) { return new Date(dt.setMonth(dt.getMonth() + n)); } dt = new Date(); console.log(add_months(dt, 10).toString());
You can also create it as prototype, if you prefer:
Date.prototype.add_months = function(w){ var date = this; date.setMonth( date.getMonth()+10 ); return date; }; var date = new Date(); console.log( date.add_months(10).toString() );