"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.
Option Explicit
Dim Before, Elapsed
Before = Now
WScript.Sleep 5000
Elapsed = Now - Before
MsgBox CDate(Elapsed) & vbCrLf & FormatNumber(Elapsed, 15)
To get a one second resolution, the OP would have to enter the birth time to
the second, subtract Now, and add/subtract a number representing the
difference in time zone between birth and the current location. The whole
number part would be age in days and the fractional part would represent the
additional fraction of a day. I think getting years and months might be
relatively easy to get, but weeks would require some extra math and a little
more math to get days, which the OP didn't ask for but may well be desired,
and a little more math to convert the remainder to hours and nutes if
desired, and seconds.
Dr. John Stockton's web site or a link from it may provide a script that
almost meets the OPs requirements. His signature typically contains links
like:
(c) John Stockton, nr London, UK. ?...@xxxxxx Turnpike
v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links,
acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see
00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm
etc.
-Paul Randall