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
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,953
Office Version
365, 2010
Platform
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
Excel Workbook
MNOP
10026/07/201029/07/201003
Course Dates
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,953
Office Version
365, 2010
Platform
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
thought text - text would result in value error no?
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,953
Office Version
365, 2010
Platform
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!
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,979
Messages
5,508,535
Members
408,688
Latest member
Bhojraj

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top