سؤال

How do I get a reliable date diff in weeks?

So far I've got

<?php
$a = new DateTime('2010-09-01');
$b = new DateTime();

$c = $a->diff($b);

Now I get a DateInterval with years, months and so on, but as far as I know a year does not have exactly 52 weeks and so doesn't a month have exactly 4 weeks.

Any suggestions how to get the real, reliable week count?

هل كانت مفيدة؟

المحلول

Maybe you can Count the days between your two dates and divide by 7?

نصائح أخرى

get the difference in days, and divide it by 7? or, if you are using older versions of PHP, get the differences in hours/minutes/seconds, and calculate it accordingly..

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top