code problem

winprog

New member
Local time
Today, 07:04
Joined
May 1, 2010
Messages
5
hello i've got a question regarding the following code made by raskew .. i understand it but there is a small part i didn;t get in the "inthold" variable he did add the date difference which is an int number to a binary result ...that i don;t get it all .. what did he want from this result .. i understand the diff part but what about the after the ADD part ..thanks for ur time guys originally posted by raskew Function fAgeYMD(StartDate As Date, EndDate As Date) As String 'Purpose: Returns the difference between StartDate and EndDate in full years, months and days 'Coded by: raskew 'To call: ' ? fAgeYMD(#7/6/54#, #10/3/84#) 'Returns: ' 30 years 2 months 28 days Dim inthold As Integer Dim dayHold As Integer inthold = Int(DateDiff("m", StartDate, EndDate)) + _ (EndDate < DateSerial(year(EndDate), month(EndDate), Day(StartDate))) If Day(EndDate) < Day(StartDate) Then dayHold = DateDiff("d", StartDate, DateSerial(year(StartDate), month(StartDate) + 1, 0)) & Day(EndDate) Else dayHold = Day(EndDate) - Day(StartDate) End If fAgeYMD = Int(inthold / 12) & " year" & IIf(Int(inthold / 12) 1, "s ", " ") _ & inthold Mod 12 & " month" & IIf(inthold Mod 12 1, "s ", " ") _ & LTrim(str(dayHold)) & " day" & IIf(dayHold 1, "s", "") End Function
 
Welcome to the site. It would help us help you to either edit your post or repost the code with proper formatting. It is difficult to read all run together like that.
 
yes i noticed that after i didit .. it was formatted the proper way before i sent it
 
hello i've got a question regarding the following code made by raskew .. i understand it but there is a small part i didn;t get in the "inthold" variable he did add the date difference which is an int number to a binary result ...that i don;t get it all .. what did he want from this result .. i understand the diff part but what about the after the ADD part ..thanks for ur time guys

originally posted by raskew

Function fAgeYMD(StartDate As Date, EndDate As Date) As String
'Purpose: Returns the difference between StartDate and EndDate in full years, months and days
'Coded by: raskew
'To call:
' ? fAgeYMD(#7/6/54#, #10/3/84#)
'Returns:
' 30 years 2 months 28 days

Dim inthold As Integer
Dim dayHold As Integer

inthold = Int(DateDiff("m", StartDate, EndDate)) + _
(EndDate < DateSerial(year(EndDate), month(EndDate), Day(StartDate)))

If Day(EndDate) < Day(StartDate) Then
dayHold = DateDiff("d", StartDate, DateSerial(year(StartDate), month(StartDate) + 1, 0)) & Day(EndDate)
Else
dayHold = Day(EndDate) - Day(StartDate)
End If

fAgeYMD = Int(inthold / 12) & " year" & IIf(Int(inthold / 12) <> 1, "s ", " ") _
& inthold Mod 12 & " month" & IIf(inthold Mod 12 <> 1, "s ", " ") _
& LTrim(str(dayHold)) & " day" & IIf(dayHold <> 1, "s", "")

End Function
 
thanks paul .. i think its now much better .. sorry it was my first time to post a thread
 
Hi and welcome to the forum -

The function in question originally posted here:

This function revolves around full months.
Unfortunately, the DateDiff() function will return a month so long
as the months differ. What's delivered doesn't necessarily represent a full month.
Code:
Example:

? datediff("m", #12/28/08#, #1/3/09#)
 1 

...obviously we're not talking a full month but rather just a few days.

The snippet that's got you troubled determines if a full month is
represented. If not, it returns a boolean True, represented as -1.
If a full month, it returns a boolean False, represented as 0.

Adding the correct response (-1 or 0) to the results of the
DateDiff("m") calculation ensures that only the number of
actual full months are included in the calculation.

Hope that clears it up. If not, please post back.

Best wishes - Bob
 
Last edited:

Users who are viewing this thread

Back
Top Bottom