How to exclude Sundays between two dates in javascript


How to exclude Sundays between two dates in javascript

In this tutorial, we will learn how to exclude Sundays between two dates in javascript. This is a very important aspect of any web application because sometimes it is required while calculating the number of days at the time of taking leave for an employee in an organization.

Assuming if someone is creating a software application related to employee management system then it will be needed for sure.

Also read, How to calculate javascript difference between two dates in days

Illustration of how to exclude Sundays between two dates in Javascript with example

Before getting started we have to understand some methods in Javascript as given below

  • date()
  • getTime()
  • getDay()

date():- This function creates a new date object with the current date and time and displays the browser’s timezone as a string.

getTime():- This function returns the time as a number of milliseconds from January 1, 1970, to the currently specified date.

getDay():- This function returns the number representation of the days of the week from Sunday to Saturday ( 0 to 6 ).

Complete Code:-

<html>
<head>
<title>ajax example</title>

</head>
<body>
	<label for="start_date"><b>Start Date:</b></label><br><br>
	<input type="date" id="start_date"><br><br>
	<label for="end_date"><b>End Date:</b></label><br><br>
	<input type="date" id="end_date" onchange="getDays()"><br><br>
	<label for="sundays"><b>Total Sundays:</b></label><br><br>
	<input type="number" id="sundays"><br><br>
	<label for="days"><b>Total Days Without Sundays:</b></label><br><br>
	<input type="number" id="days"><br><br>


<script type="text/javascript">
	function getDays()
	{
	  var from_date = new Date(document.getElementById('start_date').value);
	  var to_date = new Date(document.getElementById('end_date').value);
	  var start = new Date(from_date);
	  alert(start);
	  var finish = new Date(to_date);
	  var dayMilliseconds = 1000 * 60 * 60 * 24;
	  var weekendDays = 0;
	  while (start.getTime() <= finish.getTime()) {
	    var day = start.getDay();
	    if (day == 0) {
	        weekendDays++;
	    }
	    start = new Date(+start + dayMilliseconds);
	  }
	  var days = finish.getTime() - start.getTime();
	  document.getElementById('sundays').value = weekendDays;
	  document.getElementById('days').value = (days / (1000 * 3600 * 24))+1-(weekendDays);
	  
	}
</script>
</body>
</html>

Conclusion:- I hope this tutorial will help you to count the number of Sundays between two dates in javascript. If there is any doubt then please leave a comment below.


Leave a Comment

ceri188

ceri188

ceri188

KUPU178

HOKI311

RATU311

KUPU178

RATU311

RATU311

kupu178

kupu178

HOKI311

togel

kupu178

ratu311

mix parlay

ceri188

slot online

kupu178

KUPU178

RATU311

THOR311

THOR311

THOR311

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

kupu178

hoki311

THOR311

hoki311

togel online

kupu178

slot mahjong

ceri188

slot server thailand

ratu311

ceri188

ceri188

RATU311

punjabi virasat

mimcord.com

Centrum Medyczne

www.vrcorporate.in

phbalance.vn

THOR311

KUPU178

daftar slot gacor

hoki311

togel hongkong

kupu178

slot mahjong

ratu311

slot gacor

kupu178

kupu178

ceri188

kupu178

ceri188

THOR311

KUPU178

KUPU178

KUPU178

RATU311

kupu178

RATU311

RATU311

RATU311

KUPU178

KUPU178

RATU311

RATU311

slot online

kupu178

thor311

thor311

kupu178

kupu178

RATU311

KUPU178

THOR311

THOR311

THOR311

KUPU178

slot mahjong ways

hoki311

slot gacor

ceri188

ratu311

kupu178

Casino Baccarat Online

kupu178

kupu178

ceri188

ceri188

THOR311

THOR311

RATU311

toto macau

KUPU178

slot gacor

HOKI311

sabung ayam online

RATU311

SLOT LUCKY NEKO

CERI188

Slot Gacor

KUPU178

RATU311

RATU311

Link Spaceman

CERI188

Slot Gacor Online

THOR311

Mahjong ways

KUPU178

THOR311

THOR311

Live Casino

HOKI311

CERI188

CERI188

THOR311

THOR311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

CERI188

HOKI311 SLOT

TOTO TOGEL TOKYO

CERI188

CERI188 SITE

CERI188

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

Toto Togel

KUPU178

Slot Mahjong

CERI188

CERI188

CERI188

Slot Sweet Bonanza 2500

KUPU178

SLOT ONLINE

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178 X SLOT777

judi bola online

THOR311

KUPU178 10 GAME SLOT TERBAIK

KUPU178

KUPU178 SLOT TERPERCAYA

KUPU178 TOGEL

TOTO 4D MACAU

KUPU178

SITUS BOLA

CERI188

KUPU178

RATU311

THOR311

THOR311

HOKI311

KUPU178

RATU311

THOR311

CERI188

Slot Mahjong Ways

KUPU178

CERI188

Slot Online Resmi

KUPU178

RATU311 SLOT ONLINE

KUPU178

KUPU178: Link Akses Resmi

KUPU178: Strategi Menang Di Game Live Casino

KUPU178

KUPU178: Minimal 200 Rupiah

Slot Gacor Online

KUPU178

Mix Parlay

CERI188

CERI188

THOR311

THOR311

THOR311

THOR311

THOR311

KUPU178

Slot Thailand

CERI188

CERI188

THOR311 RTP

RATU311

RATU311

RATU311

CERI188

KUPU178 TOTO SLOT

CERI188 TOTO Singapore

THOR311

KUPU178

KUPU178

RATU311

CERI188

RATU311: Alternatif karnpuracollege

RATU311

RATU311

Thor311 Terbaru

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188: Masuk Akun Slot Super Cepat

THOR311 PRO

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

HOKI311

KUPU178

RATU311

RATU311

RATU311

RATU311

THOR311

CERI188

CERI188

RATU311

RATU311

RATU311

RATU311

Game Thor311

HOKI311

HOKI311

RATU311

HOKI311

HOKI311

THOR311

RATU311 NONTON BOLA

RATU311

HOKI311 Link QRIS EWALLET

RATU311

HOKI311 Link Apk Resmi

CERI188

RATU311 judi bola

KUPU178

situs judi bola

HOKI311

RATU311

THOR311

HOKI311

KUPU178

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

KUPU178

KUPU178

RATU311

RATU311

KUPU178

THOR311

slot thailand

judi bola

KUPU178

slot gacor

slot gacor

yakuza303

slot gacor

RATU311

THOR311