Calculate a Date Offset

jason_kelly

Board Regular
Joined
Jul 8, 2010
Messages
50
Hello,

I'd like to find out how its possible to find out the offsets between two given dates:

Example:

Date1 Date 2 Offset
07/27/2010 | 07/29/2010 | 2

You're help with this is greatly appreciated

Cheers

Jason
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Your probably referencing Text if your getting a value error

with the first date in A1, the later date in B1,

in cell C1 place a zero 0 then in D1 try =(B1+C1)-(A1+C1)
 
Upvote 0
If it was a text date, the subtraction should coerce it anyway. To add 0, it is not necessary to put it in a cell, it can be put directly in the formula.
 
Upvote 0
Not if if the text could be coerced to a date, the math of the subtraction would cause the coercion without the extra step of adding 0 to it.

Now you would get #VALUE, if there was something else in the cell that was preventing it from being coerced to a date. A space would not do this, but a non-breaking space would, and it might contain this if the data was copied from the web.

jason_kelly:
Does the following formula work?

=SUBSTITUTE(B1,CHAR(160),"")-SUBSTITUTE(A1,CHAR(160),"")


If so, you could just do a Find and Replace, Select your date columns and in the find what box, hold down you Alt key and on the numeric keypad type 0160.
In Replace With, leave it blank, click on Replace All.

and then just use, the B1-A1 formula.
 
Upvote 0
Hello Pepper,

Great solution!

The Code: =SUBSTITUTE(B1,CHAR(160),"")-SUBSTITUTE(A1,CHAR(160),"")

Works great!

Much thanks again for all your help.

Now, what I want to do with that, is create a function:

Sub test()

Dim get_date as string

get_date = Cells(cell.Row, "B").Value - Cells(cell.Row, "A").Value

End Sub

How could I implement the above into this code and spit out the magic number?

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top