JSFiddle - React, Tailwind, and code Playground

by Chinmay Pendharkar

HTML

<input type="date" id="date" value="2016-01-01">
<br>
<br>
<div id="day">

</div>

JavaScript

function getNthDayofWeek(date){
	  var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    var th = ['st', 'nd', 'rd', 'th', 'th']
  if (typeof date === "string"){
   date = new Date(date);
  }
  
  
  var backward = date.getDate();
  var n = 0;
  while(backward > 0){
   backward = backward - 7;
   n++
  }
  
  return {
		n: n,
    nth: th[n-1],
  	day: days[date.getDay()]
	}
}

var day = document.querySelector('#day');
var date = document.querySelector('#date');
date.oninput = update;
update.call(date);

function update(){
 var resp = getNthDayofWeek(this.value);
  day.innerHTML = resp.n + resp.nth + " " + resp.day + " of the month."
}