EX_BCBS Posted March 11, 2010 Share Posted March 11, 2010 Is there a way to compare a date from the data to the current system date and figure out the difference? I would like to calculate the time past from a last visit. Thank you. Link to comment Share on other sites More sharing options...
esmith Posted March 11, 2010 Share Posted March 11, 2010 Sure. What format is the date in the data? Link to comment Share on other sites More sharing options...
EX_BCBS Posted March 11, 2010 Author Share Posted March 11, 2010 Mm/dd/yyyy Link to comment Share on other sites More sharing options...
esmith Posted March 11, 2010 Share Posted March 11, 2010 //function copied from [url="http://www.mcfedries.com/JavaScript/DaysBetween.asp"]Paul McFedries'[/url] website function days_between(date1, date2) { // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24 // Convert both dates to milliseconds var date1_ms = date1.getTime() var date2_ms = date2.getTime() // Calculate the difference in milliseconds var difference_ms = Math.abs(date1_ms - date2_ms) // Convert back to days and return return Math.round(difference_ms/ONE_DAY) } //get current date var today = new Date(); //convert data for last visit to date format var lastVisit = new Date(Field("Date")); //determine days between two dates var totalDays = days_between(today, lastVisit); return totalDays; Link to comment Share on other sites More sharing options...
EX_BCBS Posted March 15, 2010 Author Share Posted March 15, 2010 Perfect, thank you! Link to comment Share on other sites More sharing options...
mhilger Posted March 15, 2010 Share Posted March 15, 2010 Great script! Thanks for posting this, Eric. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.