|
 |
|
สอบถามเกี่ยวกับการบวกวันเพิ่มอ่ะค่ะ ไม่ทราบว่าต้องเขียน code ยังไงคะ ช่วยทีนะคะ |
|
 |
|
|
 |
 |
|
Code (PHP)
$day = $_REQUEST['day'];
$this_day = date('d');
$true_day = $this_day+$day;
$date = date('Y-m')."-".$true_day;
echo $date;
|
 |
 |
 |
 |
Date :
2012-03-28 08:18:47 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ Gusto คะ หนูลองเขียนตามนี้ดู ช่วยดูอีกทีนะคะ มันไม่ได้ตามที่ต้องการค่ะ
วันที่บวกให้จริง แต่ เดือนไม่เปลี่ยนไปด้วยเลย
เช่น
วันที่ 2012-03-28
พอเอา 7 บวกเข้าไป
จะเป็น 2012-03-35
ซึ่งมันน่าจะเป็น 2012-04-04 อ่ะค่ะ
code นะคะ
day.php
Code (PHP)
<form method=post action=day1.php>
day : <input type=text name=day size=10><br>
<input type=submit value=process>
</form>
day1.php
Code (PHP)
<?
$day = $_POST['day'];
$this_day = date('d');
$true_day = $this_day+$day;
$date = date('Y-m')."-".$true_day;
echo $date;
?>
|
 |
 |
 |
 |
Date :
2012-03-28 08:45:27 |
By :
because |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
และถ้าหนูเปลี่ยนเป็น
day1.php
Code (PHP)
<?
$day = $_POST['day'];
echo date("Y-m-d", strtotime("$day day", strtotime($date)));
?>
ซึงถ้าค่า $day = 7 มันจะแสดงผลมาเป็น
1970-01-08 แทนที่จะเป็น 2012-04-04 อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2012-03-28 08:51:48 |
By :
because |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษนะครับ สะเพร่าไปหน่อย
Code (PHP)
<?
$format = 'Y-m-d';
$inputDate = date('Y-m-d');
$usersTS = strtotime($inputDate);
if($usersTS !== false){
echo date($format, strtotime('+1 day', $usersTS))."<br>";
echo date($format, strtotime('+2 day', $usersTS))."<br>";
echo date($format, strtotime('+7 day', $usersTS))."<br>";
}
?>
ดัดแปลงอีกนิด
Code (PHP)
<?
$_POST['day'] = 7;//fix รับค่ามา 7 วัน
$format = 'Y-m-d';
$inputDate = date('Y-m-d');
$day = $_POST['day'];
$day = "+".$day." day";
$usersTS = strtotime($inputDate);
if($usersTS !== false){
echo date($format, strtotime('+1 day', $usersTS))."<br>";
echo date($format, strtotime('+2 day', $usersTS))."<br>";
echo date($format, strtotime('+7 day', $usersTS))."<br>";
echo date($format, strtotime($day, $usersTS))."<br>";
}
?>
|
ประวัติการแก้ไข 2012-03-28 09:15:40
 |
 |
 |
 |
Date :
2012-03-28 09:12:54 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|