Afternoon

I need to workout the difference between two dates. Although i have two twists to the calculation.

Always a Date (dd/mm/yyyy hh:mm:ss) in A1,

If there is a date in B1 (dd/mm/yyyy hh:mm:ss), then calculate the difference between the two.

If not then calculate the difference between Now() and A1.

This is the formula I have used and works.

IF(ISBLANK(A1),"",(IF(ISBLANK(B1),(NOW()-A1),(B1-A1))

Although I need to take into account to calculate only working days (mon-Fri) which I am afraid is beyond me.

It would be nice to have it stored in the VBA code although if it can only be done as a formula then it will do.

please could you assist in finding me a solution.

Thanks in advance.

Using your example I get zero days with that formula. One possible issue is that dd:hh:mm format isn't really designed for time durations - the

ddpart is actually a day of the month (which is why it doesn't work beyond 31 days as I explained above). Another issue is whether you have "1904 date system" set - if you do then you'd get an extra day as you described (because the date system starts counting on day 1 rather than day 0)If you revert to the default 1900 date format then you won't have that problem. To do that in Excel 2003 or earlier versions:

Tools > Options > Calculation > untick "1904 date system"

or in Excel 2007 and later versions

Click on "Office" button in top left and then "Excel Options" (or in 2010 "File" then "Options") then under "Advanced" go to "When calculating this workbook" and untick "1904 date system".

Having said that, I think the formula is flawed anyway, it won't give the correct results if the B1 (or now) time is earlier in the day than the A1 time (although that doesn't explain the issue you have with 1 day instead of zero). Change to this version for more accurate results:

=NETWORKDAYS(A1,IF(B1="",N

As I alluded to in my previous reply, that formula still won't work correctly if any of the times are at the weekend, if that's a possibility change to this version:

=NETWORKDAYS(A1,IF(B1="",N

Finally, note that if you change from 1904 date system as suggested then any existing dates in your spreadsheet will change....so if you don't want to change that then I think you need to look at a formula that would return a result like "35 days 13:45" or just show hours and minutes.

If this doesn't answer your question then can you please supply the following information to cut down on the guesswork:

Which Excel version are you using?

Are you knowingly using 1904 date system - is there a reason for that?

What's the longest possible period that you might have between A1 and B1 (or A1 and now)?

Do you want to allow any of the dates to be at weekends?

regards, barry