Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Start Date minus (Years + Months + Days) = ?

In Excel, suppose I have a regular date, like: 3 February 1922

Now, I want to subtract: 86 years, 6 months, and 23 days.

1) How can I do this in a formula?
2) What is the correct answer?
3) What are the limitations in Excel for this type of calculation?

Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Start Date minus (Years + Months + Days) = ?

Assuming you have 03/02/1922) in A1
86 in C1
6 in D1
23 in E1

1) The formula is:
=DATE(YEAR(A1)-C1,MONTH(A1)-D1,DAY(A1)-E1)

2) The correct answer cannot be calculated by Excel (see limitations)

3) Excel computes dates as an integer number of days since 01/01/1900

HTH
--
AP

"quartz" a écrit dans le message de news:
...
In Excel, suppose I have a regular date, like: 3 February 1922

Now, I want to subtract: 86 years, 6 months, and 23 days.

1) How can I do this in a formula?
2) What is the correct answer?
3) What are the limitations in Excel for this type of calculation?

Thanks much in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Start Date minus (Years + Months + Days) = ?

You could get the correct value in VBA and output it to a cell as text
though as the VBA dates start in the year 100. Code follows (minus
robustness & error handling)

Sub Test()

Debug.Print SubtractTimeFromDate(DateSerial(1922, 2, 3), 86, 6, 23)

End Sub

Public Function SubtractTimeFromDate(startDate As Date, years, months,
days) As String

Dim endDate As Date

endDate = DateSerial(Year(startDate) - years, Month(startDate) -
months, Day(startDate) - days)

SubtractTimeFromDate = Format(endDate, "dd/mm/yyyy")

End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Start Date minus (Years + Months + Days) = ?


This works...thanks.

"Barry-Jon" wrote:

You could get the correct value in VBA and output it to a cell as text
though as the VBA dates start in the year 100. Code follows (minus
robustness & error handling)

Sub Test()

Debug.Print SubtractTimeFromDate(DateSerial(1922, 2, 3), 86, 6, 23)

End Sub

Public Function SubtractTimeFromDate(startDate As Date, years, months,
days) As String

Dim endDate As Date

endDate = DateSerial(Year(startDate) - years, Month(startDate) -
months, Day(startDate) - days)

SubtractTimeFromDate = Format(endDate, "dd/mm/yyyy")

End Function


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting days to years & months & days oldLearner57 Excel Discussion (Misc queries) 4 October 2nd 09 01:57 PM
how do i convert a number of days to years, months & days? SafetyLen Excel Discussion (Misc queries) 1 August 23rd 07 01:34 AM
HOW DO I CALCULATE THE YEARS MONTHS AND DAYS BETWEEN SEVERAL DATE Susan Excel Discussion (Misc queries) 1 June 29th 06 02:27 PM
FORMULA FOR CALCULATING YEARS, DAYS, & MONTHS BETWEEN SEVERAL DATE Sam Excel Discussion (Misc queries) 3 June 28th 06 10:34 PM
convert Days to Years, Months, Days Klaudebou Excel Discussion (Misc queries) 3 December 29th 05 10:33 PM


All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"