Search

Tutorials, tips&tricks, snippets..

#KISS: KEEP IT SIMPLE, STUPID!

Tag

date

SQL Group By Date.Day

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))

JavaScript: add month to Date object

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() );

Website Powered by WordPress.com.

Up ↑