JavaScript \ Get Date of Last Thursday -
how can date of last thursday via javascript?
if thursday today -7 days.
after format output '17 april 2016'.
var weekdays = [ "sun", "mon", "tue", "wed", "thurs", "fri", "sat" ]; function getdateforlastoccurence( strday ) { var date = new date(); var index = weekdays.indexof(strday); var difference = date.getday() - index; if (difference < 0 ) { difference = -7 - difference; } date.setdate( date.getdate() + difference ); return date; } getdateforlastoccurence( "tue" ); getdateforlastoccurence( "thurs" );
Comments
Post a Comment