Author Topic: Take Away Dates.  (Read 439 times)

0 Members and 1 Guest are viewing this topic.

Offline ego0Topic starter

  • Enthusiast
  • Posts: 58
    • View Profile
Take Away Dates.
« on: August 27, 2006, 12:55:27 PM »
Is it possible to take away two dates two be left with the difference between them to be displayed as a time (e.g) 2006,12,06 12:00 take away 2006,15,06 12:30

Would display the differnce as 3 days and 30 minutes?

Thanks

Offline jvalarta

  • Enthusiast
  • Posts: 53
    • View Profile
Re: Take Away Dates.
« Reply #1 on: August 27, 2006, 01:01:50 PM »
Yes, use the mktime function to turn the dates into unix timestamps...do the math (subtract one from the other) then use date() and mktime() to format the time difference however you need.

http://php.net/mktime
http://php.net/date

Code: [Select]
$MyDate = '2006-08-01 10:30:45';
$diff = time() - mktime(substr($MyDate,11,2),substr($MyDate,14,2),substr($MyDate,17,2),substr($MyDate,5,2), substr($MyDate,8,2), substr($MyDate,0,4));
$DaysGoneBy = ($diff/86400);