Nasıl emin hafta sonra bir tarih bulabilirsiniz?

4 Cevap

Ben hafta belli bir sayıdan sonra bir tarih bulmak gerekir. Başlangıç ​​tarihi cumartesi ise ben 16 hafta seçerseniz Örneğin, 31 Ekim 2009, ve sonra ben onaltı cumartesi sonra tarih bulmak gerekir.

Şimdiden teşekkürler.

4 Cevap

Sen kullanabilirsiniz strtotime:

// Oct 31 2009 plus 16 weeks
echo date('Y-m-d', strtotime('2009-10-31 +16 week')); // outputs 2010-02-20


// next week
echo date('Y-m-d', strtotime('+1 week')); // outputs 2009-11-07

Eğer 5.2.0 veya daha sonra PHP kullanarak ediyorsanız, kullanabileceğiniz DateTime class

<?php
$date = new DateTime('31 October 2009'); // This accepts any format that strtotime() does.

// Now add 16 weeks
$date->modify('+16 weeks');

// Now you can output it however you wish
echo $date->format('Y-m-d');
?>

Neden sadece, unix zaman kullanabilirsiniz bundan 7 * 24 * 3600 * 16 çıkarmamız ve sonra ihtiyacınız tarihten içine geri dönüştürmek değil.

This will help with the conversion back: http://php.net/manual/en/function.date.php