get month start date and end date in JavaScript

get month start date and end date in JavaScript

Hello everyone, I am going to share the code sample to get start date and end date of current month using JavaScript. All the detail as given below.


The JavaScript code

<script>
    var nowdate = new Date();
    var monthStartDay = new Date(nowdate.getFullYear(), nowdate.getMonth(), 1);
    var monthEndDay = new Date(nowdate.getFullYear(), nowdate.getMonth() + 1, 0);

    $(function () {
        $("#startDate").html(monthStartDay);
        $("#endDate").html(monthEndDay);
    });
</script>

The output look like this.


The Live demo code sample to get the month start date and end date in JavaScript as given below.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script>
        var nowdate = new Date();
        var monthStartDay = new Date(nowdate.getFullYear(), nowdate.getMonth(), 1);
        var monthEndDay = new Date(nowdate.getFullYear(), nowdate.getMonth() + 1, 0);

        $(function () {
            $("#startDate").html(monthStartDay);
            $("#endDate").html(monthEndDay);
        });
    </script>
</head>
<body>
    <h1>get month start date and end date in JavaScript</h1>
    <div>
        Month StartDate : <label id="startDate" class="color"></label>
    </div>
    <div>
        Month EndDate : <label id="endDate" class="color"></label>
    </div>
</body>
</html>

The output : go to link http://embed.plnkr.co/tO4vTm/preview


Thank you!
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book