Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date calculation in Excel97

Status
Not open for further replies.

wyld

Programmer
Apr 23, 2001
28
0
0
US

I have a column containing the date in YYYYMMDD format. I want to create a formula that will calculate how 'old' the record is.

For example, the formula would return the result of 4 for the date 20010601 (assuming today is June 5, 2001).

Thanks in advance!
 
Use the datedif function (you can look this up in the help file for examples). You can replace the date with cells that have the date in them.
Hope this helps


=DATEDIF("2001/06/01","2001/06/05","d")

A1 = 2001/06/01 A2 = 2001/06/05
=DATEDIF("A1","A2","d")
 

Thanks for the prompt help....I'll give it a try tomorrow.

*s*
 
change that a little to
=DATEDIFF("d",Date1,Date2)
Ypu may need to use DateValue or DateSerial to get a DATE type before using datediff.
Code:
on error resume next
dte1 = dateSerial(Cint(Mid(strdte,1,4)), _
                  Cint(Mid(strdte,5,2)), _
                  Cint(mid(strdte,7,2))
if err.number <> 0 then .....bad date
on err goto 0 
 [URL unfurl="true"]WWW.VBCompare.Com[/URL]
 
To calculate the rounded number of days from a YYYYMMDD format, for a date in cell D1, use the formula :

=INT(NOW()-DATE(ROUND(D1,-4)/10000,ROUND(D1,-2)/100-ROUND(D1,-4)/100,D1-ROUND(D1,-2)))

Use copy and paste from this posting. Save your fingers. :)


 

Thanks guys! Worked like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top