Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
New Member

Does anyone have a simple method for computing date differance?

Does anyone have a simple method for computing date differance?

Websphere 5.11
Oracle 9i
RequestCenter 2006.7

Is there a simplier method to determine the difference between two dates?
I have tried using java based formulas, but they do not take into account months with 28 or 30 days.

I was hoping that there is a SIMPLE built in function

example:
serviceForm.Dictionary.Field2.getValue() - serviceForm.Dictionary.Field1.getValue()

any ideas?

thank you
Daniel
Safeway Inc.

Everyone's tags (1)
5 REPLIES
New Member

Does anyone have a simple method for computing date differance?

You should use Javascript Date objects to do the calculation.  Try this (I haven't tested it entirely):

var dateStart = new Date(serviceForm.Dictionary.Field1.getValue()[0]);
var dateEnd = new Date(serviceForm.Dictionary.Field2.getValue()[0]);
var dateDiffms = dateEnd - dateStart; // Difference in milliseconds
var dateDiffDays = dateDiffms / (1000 * 60 * 60 * 24);

In both Java and JavaScript (and other non-mainframe languages) a date value is the number of millseconds since Januar

New Member

Does anyone have a simple method for computing date differance?

Keep in mind, these scripts usually dont take in cosideration weekends and holidays, etc., as you probably want business days only.

Also a user's date format preference might break your script. I will see if I can find one of my old ones....

New Member

Does anyone have a simple method for computing date differance?

One slight change.  The Date object also carries a time value, which you may want to ensure is 00:00:00.

dateStart.setHours(0,0,0,0);
dateEnd.setHours(0,0,0,0);

If you want to know more about these objects and their methods, visit www.w3schools.com/js/

Mark

New Member

Does anyone have a simple method for computing date differance?

This should work just fine.  As a tweak for slightly faster math try this for the following line:

var dateDiffDays = dateDiffms / (1000 * 60 * 60 * 24);

try

var dateDiffDays = Math.round(dateDiffms/86400000); //(1000*60*60*24)

Then you can evaluate dateDiffDays for how many days there are between your two dates.

New Member

Does anyone have a simple method for computing date differance?

"function Q3013_DataCallback(retArray, querylist)


{


 if(retArray['Q3013.SHORTDATE']!=undefined)


 {


  if (retArray['Q3013.SHORTDATE'][0].toUpperCase() != 'MM/DD/YYYY')


   {


     alert('To Order This Service, You must change the Short Date Preference in your Service Catalog profile back to the Allstate US Standard - MM/DD/YYYY');


     DatePrefCorrect = false;


   }


   else


   {


    DatePr

201
Views
0
Helpful
5
Replies
CreatePlease to create content