cclloyd9785 Posted August 13, 2011 Share Posted August 13, 2011 Was looking through the JS date/time functions and could not find it.How would I display how long it's been in days since a certain time? Link to comment Share on other sites More sharing options...
jeffman Posted August 13, 2011 Share Posted August 13, 2011 Create a date object for each date. (There are many ways to do that.) For each object, use the getTime() method to get the number of milliseconds since midnight Jan 1, 1970. Subtract the first number from the second. Now you have the number of elapsed milliseconds between the dates. Use simple math to convert milliseconds to days. Example: var d1 = new Date("August 10, 2011");var d2 = new Date();var elapsed = d2.getTime() - d1.getTime();var days = elapsed / (1000 * 60 * 60 * 24);var wholeDays = parseInt(days); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.