cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
975
Views
0
Helpful
5
Replies

Does anyone have a simple method for computing date differance?

Daniel Faust
Level 1
Level 1

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.

5 Replies 5

Mark Koontz
Level 1
Level 1

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

Emir E
Level 1
Level 1

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....

Mark Koontz
Level 1
Level 1

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

James Fuller
Level 1
Level 1

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.

Shane O'Hanlon
Level 1
Level 1

"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

Review Cisco Networking for a $25 gift card