How to calculate last friday using Javascript


Web Developer Blogs

todayDate = new Date();
LastFridayDate = new Date();

LastFridayDate.setDate(LastFridayDate.getDate()-1);

while (LastFridayDate.getDay() != 5){
LastFridayDate.setDate(LastFridayDate.getDate()-1);
}
// Friday = 5
if(todayDate.getDay() == 5) {
console.log(todayDate); //if today is Friday, it will display today date
} else {
console.log(LastFridayDate); //if today is not Friday, it will display last friday date
}

getDay – returns the day of the week (from 0 to 6) for the specified date

View original post

Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , ,
Posted in javascript

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
January 2015
M T W T F S S
« Dec   Feb »
 1234
567891011
12131415161718
19202122232425
262728293031  
Follow me on Twitter
Blog Stats
  • 75,930 hits
%d bloggers like this: