How to get difference between times in decimal in moment js? The Next CEO of Stack OverflowHow do you get a timestamp in JavaScript?How to get the children of the $(this) selector?Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?How can I get query string values in JavaScript?What is the difference between call and apply?How to decide when to use Node.js?Differences between lodash and underscoreWhat is the difference between Bower and npm?Get hours difference between two dates in Moment Js

How to implement Comparable so it is consistent with identity-equality

Does the Idaho Potato Commission associate potato skins with healthy eating?

logical reads on global temp table, but not on session-level temp table

How can I prove that a state of equilibrium is unstable?

Masking layers by a vector polygon layer in QGIS

How can a day be of 24 hours?

Could a dragon use its wings to swim?

Direct Implications Between USA and UK in Event of No-Deal Brexit

How to coordinate airplane tickets?

Upgrading From a 9 Speed Sora Derailleur?

Find a path from s to t using as few red nodes as possible

Incomplete cube

Another proof that dividing by 0 does not exist -- is it right?

Is it reasonable to ask other researchers to send me their previous grant applications?

Can a PhD from a non-TU9 German university become a professor in a TU9 university?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Finitely generated matrix groups whose eigenvalues are all algebraic

My boss doesn't want me to have a side project

Early programmable calculators with RS-232

How dangerous is XSS

Mathematica command that allows it to read my intentions

Could you use a laser beam as a modulated carrier wave for radio signal?

Is this a new Fibonacci Identity?

Why was Sir Cadogan fired?



How to get difference between times in decimal in moment js?



The Next CEO of Stack OverflowHow do you get a timestamp in JavaScript?How to get the children of the $(this) selector?Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?How can I get query string values in JavaScript?What is the difference between call and apply?How to decide when to use Node.js?Differences between lodash and underscoreWhat is the difference between Bower and npm?Get hours difference between two dates in Moment Js










0















How to get the difference between times in decimal in moment js?



For example: in: '17:39', out: '21:10'.



I try to do this code but it's not work for me:



let startTime = project[0].in;
let end = project[0].out;

startTime = moment(startTime, ['H:m']);
end = moment(end, ['H:m']);

var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
var minutes = parseInt(duration.asMinutes()) % 60;

console.log( hours, minutes );

const a = duration.asMinutes(); //moment.duration('1:30').asHours();
console.log( a );









share|improve this question


























    0















    How to get the difference between times in decimal in moment js?



    For example: in: '17:39', out: '21:10'.



    I try to do this code but it's not work for me:



    let startTime = project[0].in;
    let end = project[0].out;

    startTime = moment(startTime, ['H:m']);
    end = moment(end, ['H:m']);

    var duration = moment.duration(end.diff(startTime));
    var hours = duration.asHours();
    var minutes = parseInt(duration.asMinutes()) % 60;

    console.log( hours, minutes );

    const a = duration.asMinutes(); //moment.duration('1:30').asHours();
    console.log( a );









    share|improve this question
























      0












      0








      0








      How to get the difference between times in decimal in moment js?



      For example: in: '17:39', out: '21:10'.



      I try to do this code but it's not work for me:



      let startTime = project[0].in;
      let end = project[0].out;

      startTime = moment(startTime, ['H:m']);
      end = moment(end, ['H:m']);

      var duration = moment.duration(end.diff(startTime));
      var hours = duration.asHours();
      var minutes = parseInt(duration.asMinutes()) % 60;

      console.log( hours, minutes );

      const a = duration.asMinutes(); //moment.duration('1:30').asHours();
      console.log( a );









      share|improve this question














      How to get the difference between times in decimal in moment js?



      For example: in: '17:39', out: '21:10'.



      I try to do this code but it's not work for me:



      let startTime = project[0].in;
      let end = project[0].out;

      startTime = moment(startTime, ['H:m']);
      end = moment(end, ['H:m']);

      var duration = moment.duration(end.diff(startTime));
      var hours = duration.asHours();
      var minutes = parseInt(duration.asMinutes()) % 60;

      console.log( hours, minutes );

      const a = duration.asMinutes(); //moment.duration('1:30').asHours();
      console.log( a );






      javascript momentjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 19:22









      Jon SudJon Sud

      327




      327






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm not totally sure what your expected output should be in your example, maybe the following code will help you.



          const moment = require('moment');
          const start = moment('21:10', 'HH:mm');
          const end = moment('17:39', 'HH:mm');
          const difference = start.diff(end);
          const duration = moment.duration(difference);
          const minutes = duration.asMinutes() % 60;
          const hours = Math.floor(duration.asMinutes() / 60);
          console.log(hours + ':' + minutes); // 3:31





          share|improve this answer

























          • Thanks but how to covert to decimal?

            – Jon Sud
            Mar 8 at 19:43











          • duration.asHours() is in decimal. Could you give an example of your expected output?

            – Michiel
            Mar 8 at 20:01











          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%2f55069681%2fhow-to-get-difference-between-times-in-decimal-in-moment-js%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I'm not totally sure what your expected output should be in your example, maybe the following code will help you.



          const moment = require('moment');
          const start = moment('21:10', 'HH:mm');
          const end = moment('17:39', 'HH:mm');
          const difference = start.diff(end);
          const duration = moment.duration(difference);
          const minutes = duration.asMinutes() % 60;
          const hours = Math.floor(duration.asMinutes() / 60);
          console.log(hours + ':' + minutes); // 3:31





          share|improve this answer

























          • Thanks but how to covert to decimal?

            – Jon Sud
            Mar 8 at 19:43











          • duration.asHours() is in decimal. Could you give an example of your expected output?

            – Michiel
            Mar 8 at 20:01















          0














          I'm not totally sure what your expected output should be in your example, maybe the following code will help you.



          const moment = require('moment');
          const start = moment('21:10', 'HH:mm');
          const end = moment('17:39', 'HH:mm');
          const difference = start.diff(end);
          const duration = moment.duration(difference);
          const minutes = duration.asMinutes() % 60;
          const hours = Math.floor(duration.asMinutes() / 60);
          console.log(hours + ':' + minutes); // 3:31





          share|improve this answer

























          • Thanks but how to covert to decimal?

            – Jon Sud
            Mar 8 at 19:43











          • duration.asHours() is in decimal. Could you give an example of your expected output?

            – Michiel
            Mar 8 at 20:01













          0












          0








          0







          I'm not totally sure what your expected output should be in your example, maybe the following code will help you.



          const moment = require('moment');
          const start = moment('21:10', 'HH:mm');
          const end = moment('17:39', 'HH:mm');
          const difference = start.diff(end);
          const duration = moment.duration(difference);
          const minutes = duration.asMinutes() % 60;
          const hours = Math.floor(duration.asMinutes() / 60);
          console.log(hours + ':' + minutes); // 3:31





          share|improve this answer















          I'm not totally sure what your expected output should be in your example, maybe the following code will help you.



          const moment = require('moment');
          const start = moment('21:10', 'HH:mm');
          const end = moment('17:39', 'HH:mm');
          const difference = start.diff(end);
          const duration = moment.duration(difference);
          const minutes = duration.asMinutes() % 60;
          const hours = Math.floor(duration.asMinutes() / 60);
          console.log(hours + ':' + minutes); // 3:31






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 19:40

























          answered Mar 8 at 19:34









          MichielMichiel

          264




          264












          • Thanks but how to covert to decimal?

            – Jon Sud
            Mar 8 at 19:43











          • duration.asHours() is in decimal. Could you give an example of your expected output?

            – Michiel
            Mar 8 at 20:01

















          • Thanks but how to covert to decimal?

            – Jon Sud
            Mar 8 at 19:43











          • duration.asHours() is in decimal. Could you give an example of your expected output?

            – Michiel
            Mar 8 at 20:01
















          Thanks but how to covert to decimal?

          – Jon Sud
          Mar 8 at 19:43





          Thanks but how to covert to decimal?

          – Jon Sud
          Mar 8 at 19:43













          duration.asHours() is in decimal. Could you give an example of your expected output?

          – Michiel
          Mar 8 at 20:01





          duration.asHours() is in decimal. Could you give an example of your expected output?

          – Michiel
          Mar 8 at 20:01



















          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%2f55069681%2fhow-to-get-difference-between-times-in-decimal-in-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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme