Belirli bir güne gün ekleyerek

2 Cevap php

Birçok örnek bu güne gün ekleyerek üzeresiniz. Ben farklı starding gün varsa Ama nasıl, bunu yapmak için?

Örneğin (çalışmıyor):

$day='2010-01-23';

// add 7 days to the date above
$NewDate= Date('$day', strtotime("+7 days"));
echo $NewDate;

Yukarıdaki örnek çalışmaz. Nasıl Tarih yerine başka bir şey koyarak starding gün değiştirmek gerekir?

2 Cevap

Lütfen koduna dayalı bir çok temel düzeltme için:

$day='2010-01-23';

// add 7 days to the date above
$NewDate = date('Y-m-d', strtotime($day . " +7 days"));
echo $NewDate;

Php.com binupillai2003 Gönderen

<?php
/*
Add day/week/month to a particular date
@param1 yyyy-mm-dd
@param1 integer
by Binu V Pillai on 2009-12-17
*/

function addDate($date,$day)//add days
{
$sum = strtotime(date("Y-m-d", strtotime("$date")) . " +$day days");
$dateTo=date('Y-m-d',$sum);
return $dateTo;
}

?>