I'm trying to get values from html input type date and time using javascript and I was wondering if someone can help me to figure out how to parse weekday as well.
Below is what I have so far,
function showDate_(getdate) {
var dateformat = getdate.split('-')
var displaydate = document.getElementById('time')
if (displaydate) {
displaydate.textContent = dateformat[1] + '-' + dateformat[2];
}
}
<input onchange="showDate(this.value)" type="date" class="date" />
<div id="time"></div>
You can try like this,
function getDay() {
const week_of_day_arr = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var dateString = document.getElementById('date').value
var day = week_of_day_arr[new Date(dateString).getDay()];
console.log(day);
}
document.getElementById('btn').addEventListener("click", getDay)
<input type="text" id="date" placeholder="Enter Date (YYYY-MM-DD)" />
<button id="btn">Get Day</button>
to fetch day of week from current date which you will pass.
your_date_string is your date in the form of yyyy-mm-dd.
Give it a try. It will work.