LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Fredrik Wahlgren
 
Posts: n/a
Default


"Lyle" wrote in message
...
Hello. I am fairly familiar with Excel and have been racking my brain

trying
to figure a formula out. Here is the scenario. The military uses dates

in
this order yyyymmdd ( i.e. 20050401 is April 1, 2005). I have two colums

of
data in this fomat and I want to subtract one from the other to give me
atleast a total number of months and years. For example 19971015 minus
19600212. The long hand answer is 37y08m03d. I have 3190 of these I must
compute. Any help out there?
--
Lyle


I have created a simple UDF which works for the example you gave. Start the
Visual Basic Editor, insert a module and paste this

Public Function MilDateDiff(ByVal date1 As String, date2 As String) As
String
Dim d1 As Date
Dim d2 As Date
Dim sDiff As String
d1 = DateSerial(Left(date1, 4), Mid(date1, 5, 2), Right(date1, 2))
d2 = DateSerial(Left(date2, 4), Mid(date2, 5, 2), Right(date2, 2))

sDiff = CStr(Year(d2) - Year(d1))
sDiff = sDiff + "y"

sDiff = sDiff + CStr(Month(d2) - Month(d1))
sDiff = sDiff + "m"

sDiff = sDiff + CStr(Day(d2) - Day(d1))
sDiff = sDiff + "d"

MilDateDiff = sDiff
End Function


If you enter =MilDateDiff(19600212, 19971015) this function returns 37y8m3d.
This is slightly different from 37y08m03d

/Fredrik



 
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
IF & VLOOKUP FORMULA taxmom Excel Worksheet Functions 3 March 2nd 05 03:35 PM
Match / Vlookup within an Array formula Hari Prasadh Excel Discussion (Misc queries) 3 February 3rd 05 04:37 PM
revert formula insertion to old method Don't be a pain in the ass Setting up and Configuration of Excel 0 January 24th 05 01:49 PM
Help with macro formula and variable Huge project Excel Worksheet Functions 0 December 28th 04 01:27 AM
Conversion lookup formula Manos Excel Worksheet Functions 2 November 12th 04 07:53 AM


All times are GMT +1. The time now is 02:46 AM.

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"