View Single Post
Old 06-29-2009   #6 (permalink)
Pegasus [MVP]


 
 

Re: Date duration function that returns years, months, weeks and days?


"Paul Randall" <paulr901@xxxxxx> wrote in message
news:em%23izwL%23JHA.4648@xxxxxx
Quote:

>
> "Pegasus [MVP]" <news@xxxxxx> wrote in message
> news:%230Q5uiI%23JHA.2120@xxxxxx
Quote:

>>
>> "HAL07" <yahoohal@xxxxxx> wrote in message
>> news:OOjg8bI%23JHA.4692@xxxxxx
Quote:

>>> Hi there, do anybody by chance have such a function laying around?
>>>
>>> I would like to e.g. output wscript.echo "You are " &
>>> dateduration(now(), "1980.01.04", "13:42" ) & " old."
>>>
>>> Will output:
>>> You are 29 years, x months, x weeks, x hours and x seconds old
>>>
>>>
>>>
>>> --
>>> -- HAL07, Engineering Services, Norway
>>> -- Info: social.technet.microsoft.com/Forums/ replaces a lot of the
>>> newsgroups
>>
>> Use the DateDiff function to determine the difference (in seconds)
>> between the two dates, then convert the seconds back into years, months,
>> days etc. Note that your desired output ("You are 29 years, x months") is
>> ambiguous: Are your months 28, 29, 30 or 31 days long?
>>
>> If unsure how to use the DateDiff function then I recommend that you
>> download the help file script56.chm from the Microsoft site.
>
> I always thought that the DateDif function returned a double precision
> floating point number, whose whole number part is the number of days since
> the beginning of time for the current operating system and whose
> fractional part is the fraction of the current day that has elapsed, and
> that the resolution is about one eighteenth of a second.
According to script56.chm, DateDiff returns whatever you want it to return:
Years, quarters, months, days etc. There are 10 different "intervals" you
can choose from. Double precision floating point number is not one of them.
The following is a direct quote from the help file:
=============
The following example uses the DateDiff function to display the number of
days between a given date and today:

Function DiffADate(theDate)
DiffADate = "Days from today: " & DateDiff("d", Now, theDate)
End Function
=============
Note the "d" interval specifier in the DateDiff function.


My System SpecsSystem Spec