If you are looking for a JavaScript function to get the difference between the two dates in minutes then you have come to the right place.Here is the simple Javascript code
function GetdiffinMinute()
{
var d1 = new Date("12/04/2020")
var d2 = new Date("11/04/2020")
var diff = (d1.getTime() - d2.getTime()) / 60000;
var mintdiff = Math.abs(Math.round(diff));
return mintdiff
}
Subtracting two Date objects gives you the result in milliseconds .Now we want result in minutesĀ so that Dividing the result by 1000 gives you the number of seconds. And then Dividing that value by 60 gives you the number of minutes. So you can say that divide the value by 60000 gives you difference in minutes.
Using Above Concept you can also write a generic javascript function which will return the difference between two dates in minute,hours ,days,milliseconds.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button onclick="GetdiffinMinute()" type="button">Click</button>
<script type="text/javascript">
function GetdiffinMinute()
{
var todaydate = new Date();
var Newyearday = new Date("2020-01-01");
var diffMs = (todaydate - Newyearday); //diffrence in milliseconds between now & Christmas
var diffDays = Math.floor(diffMs / 86400000); //diffrence in days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); //diffrence in hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); //diffrence in minutes
alert(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes until Christmas 2009 =)");
}
</script>
</body>
</html>
The post [Solved]-Difference between two dates in minutes Javascript appeared first on Software Development | Programming Tutorials.
Read More Articles
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- jQuery Ajax GET Example with Parameters
- How to Pass Parameters in AJAX POST?| JQuery Ajax Post Json Example
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- How to add, edit and delete rows of an HTML table with Jquery?
- Registration form with image upload in MVC using jquery Ajax
- How to make an Inline editable table in MVC using jquery?
- Insert Update Delete Using Jquery Ajax and Modal Popup in Mvc
- [Solved]-How to Upload pdf file using jquery MVC?
- Dynamically creating graphs with jQuery
- How do I filter OUT a value from DataTables?
- Reading data from directory PHP to Jquery chart
- Spring MVC, Ajax, Spanish Translation for real time messages
- Implementing Jquery from jsfiddle to own html file
- Integrate jquery.validate with bootstrap popover
- when to use ajax.load() or jquery.ajax()
- How do I make a JQuery animation stay in the same place?
- kendo ui grid row filterable wont filter an complex object
- 'Attaching' Cropit with JQuery Filer
- Mouse Scrolling and other button clicks is not working on iPhone
- How to use an input box with an keyUp function to dynamically display matched list elements
- jQuery - loop through multidimensional array and append data from next or prev array
- Should all underlying elements be disabled when a jQuery dialog is showing?
- Looping DIV block after it has been filled with 3 items with PHP
- Set-global header and footer methods
- Create or Update cookie array in Jquery
- Render/redirect to an existing JQuery dialog window
- Calling a PHP function without refresh
- Cannot fetch URL using an ajax call, but can via Postman
- Hide Validation messages onLoad ? Knockout
- Layout was broken in codeigniter and some jquery functionalities when changing http to https
- can't prefill a kendo-inputfield
- jQuery blur on inputs of the same name, not indivdual radio buttons
- How to access ajax json input in restful webservice?
- OverWrite A Class Which Is Located Somewhere
- combine onLoad, onResize and onRefresh in jquery
- Adding a child to each li individually
- How can I insert a <tr> element into a dynamic table?
- Dynamic row file name into textbox
- Adding a diagonal show / hide with jquery
- Revert a jQuery function, from xml to html and back
- Change class in viewport bootstrap
- Why does this piece of code always return "no_conflict"?
- Ajax Loader Gif not working in IE or Chrome
- Jquery dynamic selector error
- switch case not working in scroll function in jquery
- Ease Transition Effect For Dimming Screen When Video Is Played
- FullCalendar and Event DateTIme format in different browsers
- Selecting a div within the n'th element of an unordered list
- Loop through a table using JQuery to check the state of checkbox
- Jquery resize() on resizing window
- Using vtiger webserices to login with jquery
- Further Regex sums
- Toggle of header-bar
- Appending a row to the table jQuery
- setup URL Destination Goals withing jQuery
- How to unbind Trigger event added from external js file
- Check page title is contained within link attribute and assign active class using jQuery
- Connect JQuery .ajax function to controller function
- Angular table and HTML Checked Boxes with Disabling Feature in Remaining Checked Boxes
- I have added two buttons addOption and removeOption and i have written jquery for that but remove button is not working
- jquery if clicked multiple times
- Implementation of knockout dynamic add row
- jQuery stop infinite scroll triggering untill next page is loaded
- Yelp API, OAuth; Invalid signature. Expected signature base string
- Jquery ui draggable mobile version
- ajax response function can't redirect the page
- Request fails with jquery-ajax but succeeded with curl
- Issue with z-indexes within an iframe
- Change jqplot renderer to LogAxisRenderer on button press
- I want to hide the files extensions in my breadcrumbs
- Allow user to click a div away and remember
- preserve bootstrap clicked tab on page refresh even if markup loaded by angular
- collapse and expand nestable list by default
- HiddenField coming back as blank in the code behind
- How to shuffle an Object
- Using Ajax/JQuery to make a search form functional
- jQuery hide() Cannot get 'duration' setting to be recognized
- How can I stop tinyMCE from remembering last window size?
- Ipad checkbox/radiobutton action slow
- Window trigger function doesn't work in Jquery
- jQuery Slide Effect is Jerky
- AJAX call not redirecting
- Starting and stopping Angular Flexsllider
- How to send data from html to MongoDB using Python Flask
- LiScroll - Auto Update <UL> from PHP file after each scroll
- Jquery Cycle-stop after first slide
- Hide/display rows with multiple different classes
- Code to increase the iframe height not working in Google Chrome
- jQuery dialog bug?
- Image Slideshow Stops Displaying after the Final Image
- Javascript into Coffee
- How to turn music on and off with one button?
- gridster not using callback function
- Prevent duplicates in two different ng-repeats
- Traversing through Javascript Object searching for key values
- Input validation for Number (user cant input less than 163)
- jQuery code only works at times?
- Set Cookie with PHP Check with Jquery
- storing active page to server with jquery and ajax
- How to retrieve text of li tag for each associated checkbox using php and jquery
- Loading multile php Files with Ajax
- BxSlider multiple slideshows
- Compatibility a jquery code in various browsers
- How to automatically show modal with 5 seconds delay with qTip plugin?
- Populating Listbox with Jquery calls onClick two times
- Offset javascript scroll: cannot read property 'top' of undefined error
- Updating page info using jQuery from a PHP script that performs an external connection
- how can i refresh only when page has changes
- How to close responsive navigation dropdown after clicking a navigation link
- How to do img validation
- (Drupal) How to only target elements within node with jQuery?
- How to add jQuery Carousel script to Bootstrap layout
- Hide the copy paste pop that comes up when user select text cordova.
- Saving HTML to MySQL via MVC post
- JS page redirect not firing
- jQuery .get works inline but not in an external file
- Json object to varible to html with jquery
- Angularjs clear multiple filters on button click
- The 2nd Owl-carousel slider doesn't load
- How can i update column value using ui-grid
- Access selected values from dropdown
- Sending request to domain using jquery ajax
- Not getting value of text input field
- Add quantity Prestashop button cannot read property 'top', why?
- Javascript performance when calling functions within html tags
- Getting undefined in dropdown from json content
- Edit OR Drag with same click
- jquery load() is duplicating div layer instead of re-populating the content
- Wordpress Slider PHP adding Title in thumbnail
- How can i get textField value from ext.net <items> through jquery
- Image randomizer - jQuery
- How to add a jQuery Plugin to Contao
- jQuery not work with new clone element
- Set text input in its own scope
- problems with InAppBrowser on dynamic links
- jQuery AJAX call in Wordpress Plugin Not Working
- Create a div with jquery and open it in full screen
- how can i make fixed tree view in asp.net
- Load data on scrolling right
- CodeIgniter Bootstrap Multiselect
- css not applied for 1st time but applies 2nd time onwards
- jQuery Validate - cannot submit form successfully more than once
- Jquery ui Dialog in an MVC listing table
- How to pass variables to JavaScript?
- Increment javascript variable function onclick
- ajaxSuccess event firing sequence
- BackboneJS Magnific Popup not working
- jQuery e.preventDefault not working only on first click
- Show sum of input fields immediately
- Jquery scrolltop Loop between anchors
- Button Failing to Perform Function jQuery
- Fancybox 2 opening at top of page
- Unable to bind dropdowlist using jQuery in asp .net page
- storing json element into javascript array
- How to make a css animation that animates in and out by clicking
- Jquery Binding Events to Multiple Instances on a Page
- How div will show in the vertical coordinates 20px when I click on the link
- File uploaded via jQuery Filer not validating
- radio buttons on click border color