python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions