Moment js to get day name from date example; In this tutorial we will show you how to get day name from date using jQuery moment js. In can use to get day name from date using moment js in jquery, javascript, vuejs, react, anguler js etc.
Moment js provide us format(‘dddd’) to get day name from date in jquery moment js easy way.
Syntax:
let someDate = moment('02-01-2022', 'DD-MM-YYYY');
let dayName = someDate.format('dddd');
Example:
<!DOCTYPE html>
<html>
<head>
<title>moment js get day name from date</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>
</head>
<body>
<h1>jquery moment js get day name from date</h1>
</body>
<script type="text/javascript">
let date1 = moment('02-01-2022', 'DD-MM-YYYY');
let dayName1 = date1.format('dddd');
console.log(dayName1);
let date2 = moment();
let dayName2 = date2.format('dddd');
console.log(dayName2);
</script>
</html>
Output:
Sunday // date day
Thursday //today date
Hope this example help you.