문제

I have a database with different domains and the dates when they were registered and I need to show when they will be expired (1 year registration). For example:

domain1.com - registered 11/19/2012 (mm-dd-yyyy) - expires in 365 days. domain2.com - registered 11/20/2011 (mm-dd-yyyy) - expires in 1 day.

I have been looking for different options and questions (i.e. How to calculate the difference between two dates using PHP?) but they are a little bit different (I don't need years to take into account) and I am not an expert in PHP and dates.

I think that one option could be removing from the total the difference of years (*365) but I will not take into account years of 366.

Thank you in advanced! Regards,

Paul

도움이 되었습니까?

해결책

You may useful this example.

$date1 = "11/19/2012";
$date2 = "11/20/2011";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);

Try it & provide appropriate response !!

다른 팁

Alternatively you could use the databases date functions to work this out for you.. with mysql it would be along the lines of

SELECT DATEDIFF(start_date, NOW()) AS days_remaining FROM table_name

See here for more info:

http://www.w3schools.com/sql/func_datediff_mysql.asp

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top