Solved

Excel 2010 - Date arithmetic BEFORE 1900 (1774 up to 1900)

Posted on 2013-06-02
7
2,621 Views
Last Modified: 2013-06-06
Hi:
I need to compute the number of days/months/years on a group of dates from 1700 to 1900.  I've got about 100 dates I need to compute durations on.
How can I do this?
Example:  October 7, 1779 to January 13, 1800
How many days/months/years.
0
Comment
Question by:brothertruffle880
  • 3
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
Comment Utility
VBA supports dates before 1900, but Excel does not.  So, you could roll your own function in VBA to do this.

It would be much easier to download John Walkenbach's Power Utility Pak add-in, though: http://spreadsheetpage.com/index.php/pupv7/home/

It includes functions that handle pre-1900 dates.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Try adding 400 years to all dates with a formula like this

=VALUE(SUBSTITUTE(A1,RIGHT(A1,4),RIGHT(A1,4)+400))

and then you can get the date difference.
0
 
LVL 14

Expert Comment

by:Faustulus
Comment Utility
I created a few UDFs which you can test on the attached workbook. They require that the dates are entered as Text on the worksheet. You can either format the cells as Text or precede your entries with an apostrophe which has the same effect. If you wish to install the functions in your workbook I suggest that you drag the entire module 'DateMan' to your own project and then save your file in XLSM format.
You can change the sequence of year, month and day to your liking. Just change the sequence of the Nds enumerations to match what you enter in the cells you want evaluated. You can also change the Date separator, just below the enum just mentioned, before the actual code starts.
There are samples of how to call the functions on the worksheet.
These are the functions available:-
YEARDIFF, MONTHDIFF, DAYDIFF - These functions were created to allow you to calculate the years, months and days between two dates. They will work on modern days as well as on historical ones. Note that the MONTHDIFF can be used to count the entire difference in months. Please observe how it is deployed in the worksheet.
DATESERIAL / HDATESERIAL - The former is designed as a UDF to call the latter which is designed as VBA function. The HDATESERIAL gives a number to each day since January 1, 0000, also converting dates entered as Text. This would enable you to sort your entries by date.
Finally, there is HWEEKDAY which works very much like VBA's own WEEKDAY function, largely because it utilizes that function. If Sunday is the first day of the week (the WEEKDAY function allows you to select your first day of the week), Monday would be the second. Hence, the result you see in the worksheet confirms that Charlemagne was crowned on a Tuesday, on Christmas Day in the year 800. Perhaps this function will be useful to you in some way.
EXX-130602-Dates-from-0000.xlsm
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
Faustulus,

I have not checked all of your UDFs, but your HDATESERIAL function has a logical flaw in how it handles leap years.

Specifically, a year ending in "00" is only a leap year if it is divisible by 400.  Your code has it backward: your code makes the years divisible by 400 a standard year, and the "00" years that are not evenly divisible by 400 leap years.  (Of course, Excel treats 1900 as a leap year--incorrectly--while VBA does not.)

Also, keep in mind that when the Gregorian calendar was adopted, there was a 10-day skip: 1582-10-04 was immediately followed by 1582-10-15.  Your UDF makes no adjustment for that, so any date calculation that spans that adjustment will be off by 10 days.

:)

Patrick
0
 
LVL 14

Assisted Solution

by:Faustulus
Faustulus earned 250 total points
Comment Utility
Patrick,

It's all that late night hobbying that produces the errors. :-)
The wrong treatment of leap years in my procedure HDATESERIAL isn't one of them, though. Please take another look. Perhaps I am blind on that eye even in the light of morning.

The Gregorian skip is another can of worms. Thank you for pointing this out to me. I have added the function 'GregorianSkip' which makes this adjustment adjustable in view of the different dates on which different countries made different changes to their then calendars.

The attached version of the same file previously uploaded has one correction, a number of improvements - in addition to the above - and doesn't feature the HWEEKDAY function any more. In order to determine the weekday of Charlemagne's coronation one may not be able to work backward in leaps of 7 days from today because the precise number of intervening days is subject to some doubt where sovereigns, both wise, haughty and practical, gave or took a few unaccounted days at their whim (or the advice of their tax consultants) in order to stay abreast of science's latest enlightenment during the otherwise dark ages.
EXX-130603-Dates-from-0000.xlsm
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
Comment Utility
For my prior comment, I used the following test cases...

=HDATESERIAL(1800,1,1)   ---->    657447
=HDATESERIAL(1800,3,1)   ---->    657507

Diff of 60, implying there is a Feb 29 (thus a leap year)

=HDATESERIAL(1900,1,1)   ---->    693972
=HDATESERIAL(1900,3,1)   ---->    694032

Diff of 60, implying there is a Feb 29 (thus a leap year)

=HDATESERIAL(2000,1,1)   ---->    730496
=HDATESERIAL(2000,3,1)   ---->    730555

Diff of 59, implying there is no Feb 29 (thus not a leap year)
0
 
LVL 14

Assisted Solution

by:Faustulus
Faustulus earned 250 total points
Comment Utility
Yes, Patrick, it was the blindness. Thank you for your assistance.
I attach another version of the workbook which - I guarantee - has fewer errors now than it had this morning.
With three quarters of a million days gone by there are just too many ways to test and, it seems, too many ways of erring, too. I will keep on correcting while some one finds errors.
EXX-130603-Dates-from-0000.xlsm
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now