MarcomCentral (PTI) and FusionPro User Communities Calculating date differences
 Register FAQ Calendar Search Today's Posts Mark Forums Read

#1
March 11th, 2010, 07:03 AM
 EX_BCBS Junior Community Member Join Date: Nov 2009 Posts: 11
Calculating date differences

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.
#2
March 11th, 2010, 07:47 AM
 esmith Senior Contributor Join Date: Oct 2008 Location: Charlotte, NC Posts: 869
Re: Calculating date differences

Sure. What format is the date in the data?
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
#3
March 11th, 2010, 07:50 AM
 EX_BCBS Junior Community Member Join Date: Nov 2009 Posts: 11
Re: Calculating date differences

Mm/dd/yyyy
#4
March 11th, 2010, 01:32 PM
 esmith Senior Contributor Join Date: Oct 2008 Location: Charlotte, NC Posts: 869
Re: Calculating date differences

Code:
```//function copied from Paul McFedries' 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);

__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
#5
March 15th, 2010, 06:15 AM
 EX_BCBS Junior Community Member Join Date: Nov 2009 Posts: 11
Re: Calculating date differences

Perfect, thank you!
#6
March 15th, 2010, 07:34 AM
 mhilger Senior Contributor Join Date: Aug 2008 Location: Chicago Posts: 325
Re: Calculating date differences

Great script! Thanks for posting this, Eric.
__________________
--Mark Hilger