Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get all dates between two dates in moment js

<!DOCTYPE html>
<html>
<head>
    <title>jquery moment example - NiceSnippets.com</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 example - NiceSnippets.com</h1>
</body>
<script type="text/javascript">
    var getDaysBetweenDates = function(startDate, endDate) {
        var now = startDate.clone(), dates = [];
  
        while (now.isSameOrBefore(endDate)) {
            dates.push(now.format('MM/DD/YYYY'));
            now.add(1, 'days');
        }
        return dates;
    };
  
    var startDate = moment('2021-01-01');
    var endDate = moment('2021-01-06');
  
    var dateList = getDaysBetweenDates(startDate, endDate);
    console.log(dateList);
</script>
</html>
Source by www.nicesnippets.com #
 
PREVIOUS NEXT
Tagged: #dates #dates #moment #js
ADD COMMENT
Topic
Name
6+1 =