Calculate difference between dates up to javascript minutes!

Asked

Viewed 1,215 times

5

I have the following date on an input: 25/09/2016 11:20:00 for example. I need to calculate the difference for the current date and return at least to the minutes. It can be in jquery or javascript. How do I?

1 answer

9

has tried to use the momentjs?

http://momentjs.com/docs/

its usability is quite simple looks some ex:

<script type="text/javascript" src="moment.js"></script>
<script type="text/javascript">
        var data1 = moment('19/08/2013 01:00', "DD/MM/YYYY hh:mm");
        var data2 = moment('18/08/2013 21:00', "DD/MM/YYYY hh:mm");
        var diferenca = data1.diff(data2, 'hours');

        console.log(diferenca); // 4
 </script>


<script type="text/javascript" src="moment.js"></script>
<script type="text/javascript">
        var data1 = moment('19/08/2013 01:00', "DD/MM/YYYY hh:mm");
        var data2 = moment('18/08/2013 21:00', "DD/MM/YYYY hh:mm");
        var diferenca = data1.diff(data2, 'days');

        console.log(diferenca);
</script>

in case after you do the data diff you have q do a parse just a read on the Moment page that has several good examples there with what you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.