You are here: Re: date/time calculations: calculating exact difference « PHP Programming Language « IT news, forums, messages
Re: date/time calculations: calculating exact difference

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация