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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
=b1-a1

Excel Workbook
ABC
17/27/20107/29/20102
Sheet1
 

scottylad2

Well-known Member
Joined
Feb 2, 2009
Messages
1,919
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)
 

scottylad2

Well-known Member
Joined
Feb 2, 2009
Messages
1,919

ADVERTISEMENT

Excel Workbook
MNOP
10026/07/201029/07/201003
Course Dates
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

scottylad2

Well-known Member
Joined
Feb 2, 2009
Messages
1,919

ADVERTISEMENT

thought text - text would result in value error no?
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

jason_kelly

Board Regular
Joined
Jul 8, 2010
Messages
50
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,133,163
Messages
5,657,176
Members
418,364
Latest member
Somebodycomegeetur

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
Top