Get date of the next 15th in JavaScript -


i need date of next 15th using format: 15.06.2015 23:59:59

examples:

  • so today 03.06.2015 15.06.2015 23:59:59.
  • on 12.08.2015 15.08.2015 23:59:59
  • and on 18.02.2015 15.03.2015 23:59:59

i need result in seconds.

i know how in php, failed make work javascript.

thanks lot helping!

you can try like

var date = new date();  //if 15th of current month on move next month  //need check whether use >= or > ie on 15th jun   //if want 15 jun use > else if want 15 jul use >=  var dt = date.getdate();  date.setdate(15);  if (dt >= 15) {    date.setmonth(date.getmonth() + 1);  }  date.sethours(23, 59, 59, 0);  document.write(date)


if want function returns new date object

function setnext15(date) {     var next = new date(date);     var cache = next.getdate();     next.setdate(15);     if (cache >= 15) {         next.setmonth(date.getmonth() + 1);     }     next.sethours(23, 59, 59, 0);     console.log(next, date);     return next; } 

demo: fiddle


Comments