Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 11th, 2010, 07:03 AM
EX_BCBS EX_BCBS is offline
Junior Community Member
 
Join Date: Nov 2009
Posts: 11
Default 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.
Reply With Quote
  #2  
Old March 11th, 2010, 07:47 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default 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
Reply With Quote
  #3  
Old March 11th, 2010, 07:50 AM
EX_BCBS EX_BCBS is offline
Junior Community Member
 
Join Date: Nov 2009
Posts: 11
Default Re: Calculating date differences

Mm/dd/yyyy
Reply With Quote
  #4  
Old March 11th, 2010, 01:32 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default 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);

return totalDays;
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #5  
Old March 15th, 2010, 06:15 AM
EX_BCBS EX_BCBS is offline
Junior Community Member
 
Join Date: Nov 2009
Posts: 11
Default Re: Calculating date differences

Perfect, thank you!
Reply With Quote
  #6  
Old March 15th, 2010, 07:34 AM
mhilger's Avatar
mhilger mhilger is offline
Senior Contributor
 
Join Date: Aug 2008
Location: Chicago
Posts: 326
Default Re: Calculating date differences

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:30 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.