Get the beginning of the day in timestamp using Momentjs library










0















For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.










share|improve this question


























    0















    For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
    However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.










    share|improve this question
























      0












      0








      0








      For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
      However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.










      share|improve this question














      For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
      However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.







      javascript momentjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 17:55









      Heyab ReddaHeyab Redda

      199317




      199317






















          2 Answers
          2






          active

          oldest

          votes


















          1














          moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)





          share|improve this answer























          • I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

            – Heyab Redda
            Nov 12 '18 at 18:12












          • moment(moment(val).startOf('day').unix() * 1000)

            – knighteq
            Nov 12 '18 at 18:14











          • Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

            – knighteq
            Nov 12 '18 at 18:16












          • This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

            – Heyab Redda
            Nov 12 '18 at 18:19











          • jsfiddle.net/1tmzfu8q - is this what you need?

            – knighteq
            Nov 12 '18 at 18:28



















          1














          You could do something like this:






          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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








          share|improve this answer























          • Thank you! @Akrion

            – Heyab Redda
            Nov 12 '18 at 20:23










          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',
          autoActivateHeartbeat: false,
          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%2f53267599%2fget-the-beginning-of-the-day-in-timestamp-using-momentjs-library%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)





          share|improve this answer























          • I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

            – Heyab Redda
            Nov 12 '18 at 18:12












          • moment(moment(val).startOf('day').unix() * 1000)

            – knighteq
            Nov 12 '18 at 18:14











          • Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

            – knighteq
            Nov 12 '18 at 18:16












          • This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

            – Heyab Redda
            Nov 12 '18 at 18:19











          • jsfiddle.net/1tmzfu8q - is this what you need?

            – knighteq
            Nov 12 '18 at 18:28
















          1














          moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)





          share|improve this answer























          • I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

            – Heyab Redda
            Nov 12 '18 at 18:12












          • moment(moment(val).startOf('day').unix() * 1000)

            – knighteq
            Nov 12 '18 at 18:14











          • Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

            – knighteq
            Nov 12 '18 at 18:16












          • This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

            – Heyab Redda
            Nov 12 '18 at 18:19











          • jsfiddle.net/1tmzfu8q - is this what you need?

            – knighteq
            Nov 12 '18 at 18:28














          1












          1








          1







          moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)





          share|improve this answer













          moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 18:08









          knighteqknighteq

          662




          662












          • I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

            – Heyab Redda
            Nov 12 '18 at 18:12












          • moment(moment(val).startOf('day').unix() * 1000)

            – knighteq
            Nov 12 '18 at 18:14











          • Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

            – knighteq
            Nov 12 '18 at 18:16












          • This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

            – Heyab Redda
            Nov 12 '18 at 18:19











          • jsfiddle.net/1tmzfu8q - is this what you need?

            – knighteq
            Nov 12 '18 at 18:28


















          • I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

            – Heyab Redda
            Nov 12 '18 at 18:12












          • moment(moment(val).startOf('day').unix() * 1000)

            – knighteq
            Nov 12 '18 at 18:14











          • Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

            – knighteq
            Nov 12 '18 at 18:16












          • This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

            – Heyab Redda
            Nov 12 '18 at 18:19











          • jsfiddle.net/1tmzfu8q - is this what you need?

            – knighteq
            Nov 12 '18 at 18:28

















          I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

          – Heyab Redda
          Nov 12 '18 at 18:12






          I have val = 1542769200; How and where do I use this variable in the expression that you have provided?

          – Heyab Redda
          Nov 12 '18 at 18:12














          moment(moment(val).startOf('day').unix() * 1000)

          – knighteq
          Nov 12 '18 at 18:14





          moment(moment(val).startOf('day').unix() * 1000)

          – knighteq
          Nov 12 '18 at 18:14













          Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

          – knighteq
          Nov 12 '18 at 18:16






          Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..

          – knighteq
          Nov 12 '18 at 18:16














          This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

          – Heyab Redda
          Nov 12 '18 at 18:19





          This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day

          – Heyab Redda
          Nov 12 '18 at 18:19













          jsfiddle.net/1tmzfu8q - is this what you need?

          – knighteq
          Nov 12 '18 at 18:28






          jsfiddle.net/1tmzfu8q - is this what you need?

          – knighteq
          Nov 12 '18 at 18:28














          1














          You could do something like this:






          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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








          share|improve this answer























          • Thank you! @Akrion

            – Heyab Redda
            Nov 12 '18 at 20:23















          1














          You could do something like this:






          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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








          share|improve this answer























          • Thank you! @Akrion

            – Heyab Redda
            Nov 12 '18 at 20:23













          1












          1








          1







          You could do something like this:






          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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








          share|improve this answer













          You could do something like this:






          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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








          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

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





          var timestamp = 1542769200;
          var date = moment.unix(timestamp).startOf('day')

          console.log('date:', moment.unix(timestamp).format())
          console.log('start of day:', date.format())
          console.log('new unix:', date.unix())
          console.log('test:', moment.unix(date.unix()).format())

          <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










          answered Nov 12 '18 at 19:17









          AkrionAkrion

          9,40211224




          9,40211224












          • Thank you! @Akrion

            – Heyab Redda
            Nov 12 '18 at 20:23

















          • Thank you! @Akrion

            – Heyab Redda
            Nov 12 '18 at 20:23
















          Thank you! @Akrion

          – Heyab Redda
          Nov 12 '18 at 20:23





          Thank you! @Akrion

          – Heyab Redda
          Nov 12 '18 at 20:23

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267599%2fget-the-beginning-of-the-day-in-timestamp-using-momentjs-library%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

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20