|
Posted by Mike Willbanks on 05/16/05 04:58
Hans Gruber wrote:
> Hi all,
>
> I have been struggling with a problem all day, I have been unable to come
> up with a working solution.
>
> I want to write a function which takes 2 unix timestamps and calculates
> the difference. I want it to return the difference in years, months, days,
> hours, minutes and seconds (a complete summary). Keeping into account of
> course that these are 2 real dates, I dont want it to work with 30.475 as
> an average number of days in a month, I want it to work with the supplied
> months/years.
>
> The output ought to be: there is 0 years, 7 months, 12 days, 5 hours,
> 56 minutes and 51 seconds difference.
> (I dont want the difference as in 1237438424 seconds but a complete
> summary).
Look into the date functions. There are functions in there to tell you
how many days are in the current month. Even if you wanted to do this
by hand you could create an array with each month and how many days it
has and check for a leap year.
Then use the date function to work with these.... It will work, but to
get it in your exact format might be a bit of work.
Mike
Navigation:
[Reply to this message]
|