How can I remove time from date with Moment.js?











up vote
171
down vote

favorite
19












formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LLL');
};


It displays: "28 februari 2013 09:24"



But I would like to remove the time at the end. How can I do that?



I'm using Moment.js.










share|improve this question
























  • Use Split method to separate the strings
    – AmGates
    Feb 28 '13 at 8:28















up vote
171
down vote

favorite
19












formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LLL');
};


It displays: "28 februari 2013 09:24"



But I would like to remove the time at the end. How can I do that?



I'm using Moment.js.










share|improve this question
























  • Use Split method to separate the strings
    – AmGates
    Feb 28 '13 at 8:28













up vote
171
down vote

favorite
19









up vote
171
down vote

favorite
19






19





formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LLL');
};


It displays: "28 februari 2013 09:24"



But I would like to remove the time at the end. How can I do that?



I'm using Moment.js.










share|improve this question















formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LLL');
};


It displays: "28 februari 2013 09:24"



But I would like to remove the time at the end. How can I do that?



I'm using Moment.js.







javascript date momentjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 8:11









Pang

6,8161563101




6,8161563101










asked Feb 28 '13 at 8:25









Obsivus

3,32593990




3,32593990












  • Use Split method to separate the strings
    – AmGates
    Feb 28 '13 at 8:28


















  • Use Split method to separate the strings
    – AmGates
    Feb 28 '13 at 8:28
















Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28




Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28












10 Answers
10






active

oldest

votes

















up vote
438
down vote



accepted










Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:



.startOf('day')


Ref: http://momentjs.com/docs/#/manipulating/start-of/






share|improve this answer



















  • 62




    Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
    – colllin
    Nov 6 '13 at 5:37






  • 6




    This should definetly be the accepted answer
    – Luca Steeb
    Apr 23 '15 at 20:03






  • 18




    Also be careful that this function actually mutates the original object
    – Dirk Boer
    Jul 8 '15 at 16:36








  • 4




    .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
    – Sudarshan_SMD
    Dec 13 '16 at 7:18






  • 2




    To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
    – Pang
    May 23 '17 at 8:06


















up vote
28
down vote













Use format('LL')



Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:



Moment().format('LL'); // => April 29, 2016





share|improve this answer






























    up vote
    11
    down vote













    The correct way would be to specify the input as per your requirement which will give you more flexibility.



    The present definition includes the following



    LTS : 'h:mm:ss A',
    LT : 'h:mm A',
    L : 'MM/DD/YYYY',
    LL : 'MMMM D, YYYY',
    LLL : 'MMMM D, YYYY h:mm A',
    LLLL : 'dddd, MMMM D, YYYY h:mm A'



    You can use any of these or change the input passed into moment().format().
    For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY').






    share|improve this answer




























      up vote
      6
      down vote













      formatCalendarDate = function (dateTime) {
      return moment.utc(dateTime).format('LL')
      }





      share|improve this answer






























        up vote
        3
        down vote













        With newer versions of moment.js you can also do this:



        var dateTime = moment();

        var dateValue = moment({
        year: dateTime.year(),
        month: dateTime.month(),
        day: dateTime.date()
        });


        See: http://momentjs.com/docs/#/parsing/object/.






        share|improve this answer























        • Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
          – philfreo
          Oct 26 '16 at 18:44










        • 'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
          – oldwizard
          May 17 '17 at 7:13


















        up vote
        2
        down vote













        You can also use this format:



        moment().format('ddd, ll'); // Wed, Jan 4, 2017






        share|improve this answer




























          up vote
          2
          down vote













          You can use this constructor



          moment({h:0, m:0, s:0, ms:0})


          http://momentjs.com/docs/#/parsing/object/






          console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

          console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>








          share|improve this answer























          • Add some ore description here
            – Billa
            Aug 23 at 12:45


















          up vote
          1
          down vote













          Whenever I use the moment.js library I specify the desired format this way:



          moment(<your Date goes here>).format("DD-MMM-YYYY")


          or



          moment(<your Date goes here>).format("DD/MMM/YYYY")


          ... etc I hope you get the idea



          Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds






          share|improve this answer





















          • This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
            – AJ Richardson
            Apr 2 at 21:46


















          up vote
          0
          down vote













          Try this:



          moment.format().split("T")[0]





          share|improve this answer























          • Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
            – Tom
            Nov 20 '17 at 7:49


















          up vote
          0
          down vote













          For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:



          var localeData = moment.localeData( moment.locale() ),
          llll = localeData.longDateFormat( 'llll' ),
          lll = localeData.longDateFormat( 'lll' ),
          ll = localeData.longDateFormat( 'll' ),
          longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
          var formattedDate = myMoment.format(longDateFormat);





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15130735%2fhow-can-i-remove-time-from-date-with-moment-js%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            10 Answers
            10






            active

            oldest

            votes








            10 Answers
            10






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            438
            down vote



            accepted










            Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:



            .startOf('day')


            Ref: http://momentjs.com/docs/#/manipulating/start-of/






            share|improve this answer



















            • 62




              Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
              – colllin
              Nov 6 '13 at 5:37






            • 6




              This should definetly be the accepted answer
              – Luca Steeb
              Apr 23 '15 at 20:03






            • 18




              Also be careful that this function actually mutates the original object
              – Dirk Boer
              Jul 8 '15 at 16:36








            • 4




              .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
              – Sudarshan_SMD
              Dec 13 '16 at 7:18






            • 2




              To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
              – Pang
              May 23 '17 at 8:06















            up vote
            438
            down vote



            accepted










            Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:



            .startOf('day')


            Ref: http://momentjs.com/docs/#/manipulating/start-of/






            share|improve this answer



















            • 62




              Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
              – colllin
              Nov 6 '13 at 5:37






            • 6




              This should definetly be the accepted answer
              – Luca Steeb
              Apr 23 '15 at 20:03






            • 18




              Also be careful that this function actually mutates the original object
              – Dirk Boer
              Jul 8 '15 at 16:36








            • 4




              .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
              – Sudarshan_SMD
              Dec 13 '16 at 7:18






            • 2




              To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
              – Pang
              May 23 '17 at 8:06













            up vote
            438
            down vote



            accepted







            up vote
            438
            down vote



            accepted






            Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:



            .startOf('day')


            Ref: http://momentjs.com/docs/#/manipulating/start-of/






            share|improve this answer














            Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:



            .startOf('day')


            Ref: http://momentjs.com/docs/#/manipulating/start-of/







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday









            trojek

            646729




            646729










            answered Oct 31 '13 at 6:03









            Graham Charles

            5,35332035




            5,35332035








            • 62




              Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
              – colllin
              Nov 6 '13 at 5:37






            • 6




              This should definetly be the accepted answer
              – Luca Steeb
              Apr 23 '15 at 20:03






            • 18




              Also be careful that this function actually mutates the original object
              – Dirk Boer
              Jul 8 '15 at 16:36








            • 4




              .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
              – Sudarshan_SMD
              Dec 13 '16 at 7:18






            • 2




              To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
              – Pang
              May 23 '17 at 8:06














            • 62




              Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
              – colllin
              Nov 6 '13 at 5:37






            • 6




              This should definetly be the accepted answer
              – Luca Steeb
              Apr 23 '15 at 20:03






            • 18




              Also be careful that this function actually mutates the original object
              – Dirk Boer
              Jul 8 '15 at 16:36








            • 4




              .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
              – Sudarshan_SMD
              Dec 13 '16 at 7:18






            • 2




              To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
              – Pang
              May 23 '17 at 8:06








            62




            62




            Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
            – colllin
            Nov 6 '13 at 5:37




            Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying startOf('day'), which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
            – colllin
            Nov 6 '13 at 5:37




            6




            6




            This should definetly be the accepted answer
            – Luca Steeb
            Apr 23 '15 at 20:03




            This should definetly be the accepted answer
            – Luca Steeb
            Apr 23 '15 at 20:03




            18




            18




            Also be careful that this function actually mutates the original object
            – Dirk Boer
            Jul 8 '15 at 16:36






            Also be careful that this function actually mutates the original object
            – Dirk Boer
            Jul 8 '15 at 16:36






            4




            4




            .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
            – Sudarshan_SMD
            Dec 13 '16 at 7:18




            .startOf('day') does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL'), as have been answered in this thread.
            – Sudarshan_SMD
            Dec 13 '16 at 7:18




            2




            2




            To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
            – Pang
            May 23 '17 at 8:06




            To avoid mutating the original object, use someMoment.clone().startOf('day') or moment(someMoment).startOf('day').
            – Pang
            May 23 '17 at 8:06












            up vote
            28
            down vote













            Use format('LL')



            Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:



            Moment().format('LL'); // => April 29, 2016





            share|improve this answer



























              up vote
              28
              down vote













              Use format('LL')



              Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:



              Moment().format('LL'); // => April 29, 2016





              share|improve this answer

























                up vote
                28
                down vote










                up vote
                28
                down vote









                Use format('LL')



                Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:



                Moment().format('LL'); // => April 29, 2016





                share|improve this answer














                Use format('LL')



                Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:



                Moment().format('LL'); // => April 29, 2016






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 21 at 16:53

























                answered Apr 30 '16 at 0:52









                Joshua Pinter

                23.5k8134160




                23.5k8134160






















                    up vote
                    11
                    down vote













                    The correct way would be to specify the input as per your requirement which will give you more flexibility.



                    The present definition includes the following



                    LTS : 'h:mm:ss A',
                    LT : 'h:mm A',
                    L : 'MM/DD/YYYY',
                    LL : 'MMMM D, YYYY',
                    LLL : 'MMMM D, YYYY h:mm A',
                    LLLL : 'dddd, MMMM D, YYYY h:mm A'



                    You can use any of these or change the input passed into moment().format().
                    For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY').






                    share|improve this answer

























                      up vote
                      11
                      down vote













                      The correct way would be to specify the input as per your requirement which will give you more flexibility.



                      The present definition includes the following



                      LTS : 'h:mm:ss A',
                      LT : 'h:mm A',
                      L : 'MM/DD/YYYY',
                      LL : 'MMMM D, YYYY',
                      LLL : 'MMMM D, YYYY h:mm A',
                      LLLL : 'dddd, MMMM D, YYYY h:mm A'



                      You can use any of these or change the input passed into moment().format().
                      For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY').






                      share|improve this answer























                        up vote
                        11
                        down vote










                        up vote
                        11
                        down vote









                        The correct way would be to specify the input as per your requirement which will give you more flexibility.



                        The present definition includes the following



                        LTS : 'h:mm:ss A',
                        LT : 'h:mm A',
                        L : 'MM/DD/YYYY',
                        LL : 'MMMM D, YYYY',
                        LLL : 'MMMM D, YYYY h:mm A',
                        LLLL : 'dddd, MMMM D, YYYY h:mm A'



                        You can use any of these or change the input passed into moment().format().
                        For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY').






                        share|improve this answer












                        The correct way would be to specify the input as per your requirement which will give you more flexibility.



                        The present definition includes the following



                        LTS : 'h:mm:ss A',
                        LT : 'h:mm A',
                        L : 'MM/DD/YYYY',
                        LL : 'MMMM D, YYYY',
                        LLL : 'MMMM D, YYYY h:mm A',
                        LLLL : 'dddd, MMMM D, YYYY h:mm A'



                        You can use any of these or change the input passed into moment().format().
                        For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY').







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 1 '17 at 17:07









                        Sahil Jain

                        6561614




                        6561614






















                            up vote
                            6
                            down vote













                            formatCalendarDate = function (dateTime) {
                            return moment.utc(dateTime).format('LL')
                            }





                            share|improve this answer



























                              up vote
                              6
                              down vote













                              formatCalendarDate = function (dateTime) {
                              return moment.utc(dateTime).format('LL')
                              }





                              share|improve this answer

























                                up vote
                                6
                                down vote










                                up vote
                                6
                                down vote









                                formatCalendarDate = function (dateTime) {
                                return moment.utc(dateTime).format('LL')
                                }





                                share|improve this answer














                                formatCalendarDate = function (dateTime) {
                                return moment.utc(dateTime).format('LL')
                                }






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited May 23 '17 at 8:13









                                Pang

                                6,8161563101




                                6,8161563101










                                answered Feb 28 '13 at 8:31









                                AmGates

                                1,6781326




                                1,6781326






















                                    up vote
                                    3
                                    down vote













                                    With newer versions of moment.js you can also do this:



                                    var dateTime = moment();

                                    var dateValue = moment({
                                    year: dateTime.year(),
                                    month: dateTime.month(),
                                    day: dateTime.date()
                                    });


                                    See: http://momentjs.com/docs/#/parsing/object/.






                                    share|improve this answer























                                    • Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                      – philfreo
                                      Oct 26 '16 at 18:44










                                    • 'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                      – oldwizard
                                      May 17 '17 at 7:13















                                    up vote
                                    3
                                    down vote













                                    With newer versions of moment.js you can also do this:



                                    var dateTime = moment();

                                    var dateValue = moment({
                                    year: dateTime.year(),
                                    month: dateTime.month(),
                                    day: dateTime.date()
                                    });


                                    See: http://momentjs.com/docs/#/parsing/object/.






                                    share|improve this answer























                                    • Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                      – philfreo
                                      Oct 26 '16 at 18:44










                                    • 'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                      – oldwizard
                                      May 17 '17 at 7:13













                                    up vote
                                    3
                                    down vote










                                    up vote
                                    3
                                    down vote









                                    With newer versions of moment.js you can also do this:



                                    var dateTime = moment();

                                    var dateValue = moment({
                                    year: dateTime.year(),
                                    month: dateTime.month(),
                                    day: dateTime.date()
                                    });


                                    See: http://momentjs.com/docs/#/parsing/object/.






                                    share|improve this answer














                                    With newer versions of moment.js you can also do this:



                                    var dateTime = moment();

                                    var dateValue = moment({
                                    year: dateTime.year(),
                                    month: dateTime.month(),
                                    day: dateTime.date()
                                    });


                                    See: http://momentjs.com/docs/#/parsing/object/.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Feb 2 at 17:59









                                    FlavorScape

                                    4,89365492




                                    4,89365492










                                    answered Sep 10 '15 at 16:52









                                    Torben Rahbek Koch

                                    550314




                                    550314












                                    • Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                      – philfreo
                                      Oct 26 '16 at 18:44










                                    • 'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                      – oldwizard
                                      May 17 '17 at 7:13


















                                    • Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                      – philfreo
                                      Oct 26 '16 at 18:44










                                    • 'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                      – oldwizard
                                      May 17 '17 at 7:13
















                                    Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                    – philfreo
                                    Oct 26 '16 at 18:44




                                    Wouldn't it be date: dateTime.date() instead of day: dateTime.date()?
                                    – philfreo
                                    Oct 26 '16 at 18:44












                                    'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                    – oldwizard
                                    May 17 '17 at 7:13




                                    'day and date key both mean day-of-the-month.' from the docs. day works pre version 2.8.4.
                                    – oldwizard
                                    May 17 '17 at 7:13










                                    up vote
                                    2
                                    down vote













                                    You can also use this format:



                                    moment().format('ddd, ll'); // Wed, Jan 4, 2017






                                    share|improve this answer

























                                      up vote
                                      2
                                      down vote













                                      You can also use this format:



                                      moment().format('ddd, ll'); // Wed, Jan 4, 2017






                                      share|improve this answer























                                        up vote
                                        2
                                        down vote










                                        up vote
                                        2
                                        down vote









                                        You can also use this format:



                                        moment().format('ddd, ll'); // Wed, Jan 4, 2017






                                        share|improve this answer












                                        You can also use this format:



                                        moment().format('ddd, ll'); // Wed, Jan 4, 2017







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jan 4 '17 at 7:54









                                        Hashmita Raut

                                        416




                                        416






















                                            up vote
                                            2
                                            down vote













                                            You can use this constructor



                                            moment({h:0, m:0, s:0, ms:0})


                                            http://momentjs.com/docs/#/parsing/object/






                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>








                                            share|improve this answer























                                            • Add some ore description here
                                              – Billa
                                              Aug 23 at 12:45















                                            up vote
                                            2
                                            down vote













                                            You can use this constructor



                                            moment({h:0, m:0, s:0, ms:0})


                                            http://momentjs.com/docs/#/parsing/object/






                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>








                                            share|improve this answer























                                            • Add some ore description here
                                              – Billa
                                              Aug 23 at 12:45













                                            up vote
                                            2
                                            down vote










                                            up vote
                                            2
                                            down vote









                                            You can use this constructor



                                            moment({h:0, m:0, s:0, ms:0})


                                            http://momentjs.com/docs/#/parsing/object/






                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>








                                            share|improve this answer














                                            You can use this constructor



                                            moment({h:0, m:0, s:0, ms:0})


                                            http://momentjs.com/docs/#/parsing/object/






                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>








                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>





                                            console.log( moment().format('YYYY-MM-DD HH:mm:ss') )

                                            console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )

                                            <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Nov 21 at 22:34

























                                            answered Aug 23 at 12:29









                                            EquaPro

                                            1012




                                            1012












                                            • Add some ore description here
                                              – Billa
                                              Aug 23 at 12:45


















                                            • Add some ore description here
                                              – Billa
                                              Aug 23 at 12:45
















                                            Add some ore description here
                                            – Billa
                                            Aug 23 at 12:45




                                            Add some ore description here
                                            – Billa
                                            Aug 23 at 12:45










                                            up vote
                                            1
                                            down vote













                                            Whenever I use the moment.js library I specify the desired format this way:



                                            moment(<your Date goes here>).format("DD-MMM-YYYY")


                                            or



                                            moment(<your Date goes here>).format("DD/MMM/YYYY")


                                            ... etc I hope you get the idea



                                            Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds






                                            share|improve this answer





















                                            • This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                              – AJ Richardson
                                              Apr 2 at 21:46















                                            up vote
                                            1
                                            down vote













                                            Whenever I use the moment.js library I specify the desired format this way:



                                            moment(<your Date goes here>).format("DD-MMM-YYYY")


                                            or



                                            moment(<your Date goes here>).format("DD/MMM/YYYY")


                                            ... etc I hope you get the idea



                                            Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds






                                            share|improve this answer





















                                            • This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                              – AJ Richardson
                                              Apr 2 at 21:46













                                            up vote
                                            1
                                            down vote










                                            up vote
                                            1
                                            down vote









                                            Whenever I use the moment.js library I specify the desired format this way:



                                            moment(<your Date goes here>).format("DD-MMM-YYYY")


                                            or



                                            moment(<your Date goes here>).format("DD/MMM/YYYY")


                                            ... etc I hope you get the idea



                                            Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds






                                            share|improve this answer












                                            Whenever I use the moment.js library I specify the desired format this way:



                                            moment(<your Date goes here>).format("DD-MMM-YYYY")


                                            or



                                            moment(<your Date goes here>).format("DD/MMM/YYYY")


                                            ... etc I hope you get the idea



                                            Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Oct 16 '17 at 9:42









                                            Adrian Grzywaczewski

                                            3481314




                                            3481314












                                            • This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                              – AJ Richardson
                                              Apr 2 at 21:46


















                                            • This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                              – AJ Richardson
                                              Apr 2 at 21:46
















                                            This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                            – AJ Richardson
                                            Apr 2 at 21:46




                                            This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.)
                                            – AJ Richardson
                                            Apr 2 at 21:46










                                            up vote
                                            0
                                            down vote













                                            Try this:



                                            moment.format().split("T")[0]





                                            share|improve this answer























                                            • Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                              – Tom
                                              Nov 20 '17 at 7:49















                                            up vote
                                            0
                                            down vote













                                            Try this:



                                            moment.format().split("T")[0]





                                            share|improve this answer























                                            • Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                              – Tom
                                              Nov 20 '17 at 7:49













                                            up vote
                                            0
                                            down vote










                                            up vote
                                            0
                                            down vote









                                            Try this:



                                            moment.format().split("T")[0]





                                            share|improve this answer














                                            Try this:



                                            moment.format().split("T")[0]






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Aug 28 '17 at 23:19









                                            Moe A

                                            3,74571227




                                            3,74571227










                                            answered Aug 28 '17 at 22:59









                                            Keith Blanchard

                                            1




                                            1












                                            • Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                              – Tom
                                              Nov 20 '17 at 7:49


















                                            • Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                              – Tom
                                              Nov 20 '17 at 7:49
















                                            Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                            – Tom
                                            Nov 20 '17 at 7:49




                                            Watch out with this method, as 1993-06-07T22:00:00.000Z will result as 1993-06-07 whereas it is the start of the day of 1993-06-08
                                            – Tom
                                            Nov 20 '17 at 7:49










                                            up vote
                                            0
                                            down vote













                                            For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:



                                            var localeData = moment.localeData( moment.locale() ),
                                            llll = localeData.longDateFormat( 'llll' ),
                                            lll = localeData.longDateFormat( 'lll' ),
                                            ll = localeData.longDateFormat( 'll' ),
                                            longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
                                            var formattedDate = myMoment.format(longDateFormat);





                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:



                                              var localeData = moment.localeData( moment.locale() ),
                                              llll = localeData.longDateFormat( 'llll' ),
                                              lll = localeData.longDateFormat( 'lll' ),
                                              ll = localeData.longDateFormat( 'll' ),
                                              longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
                                              var formattedDate = myMoment.format(longDateFormat);





                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:



                                                var localeData = moment.localeData( moment.locale() ),
                                                llll = localeData.longDateFormat( 'llll' ),
                                                lll = localeData.longDateFormat( 'lll' ),
                                                ll = localeData.longDateFormat( 'll' ),
                                                longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
                                                var formattedDate = myMoment.format(longDateFormat);





                                                share|improve this answer












                                                For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:



                                                var localeData = moment.localeData( moment.locale() ),
                                                llll = localeData.longDateFormat( 'llll' ),
                                                lll = localeData.longDateFormat( 'lll' ),
                                                ll = localeData.longDateFormat( 'll' ),
                                                longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
                                                var formattedDate = myMoment.format(longDateFormat);






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Apr 2 at 21:58









                                                AJ Richardson

                                                4,0172948




                                                4,0172948






























                                                     

                                                    draft saved


                                                    draft discarded



















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15130735%2fhow-can-i-remove-time-from-date-with-moment-js%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                                                    Alexandru Averescu

                                                    Trompette piccolo