22 November 2022

บวกลบตัวแปล วันที่ บน php

 

บวกลบตัวแปล วันที่ บน php

(+/- Date from php )

ตัวอย่างและ ผลลัพท์หลังจาก ใช้งานคำสั่ง
เช่นถ้าต้องการ ลบวันที่จากวันปัจจุบัน 30 วัน
ก็เรียกวันที่ปัจจุบันด้วยคำสั่ง "now" และทำการ -30ตามตัวอย่างด้านล่าง

date("Y-m-d", strtotime("now -30 Day"))

และตัวอย่างอื่นๆ ครับ

echo Date("Y-m-d", strtotime("2013-01-01 +1 Month -1 Day"));// 2013-01-31
echo Date("Y-m-d", strtotime("2013-01-31 +1 Month -3 Day")); // 2013-02-28

echo Date("Y-m-d", strtotime("2013-01-31 +2 Month")); // 2013-03-31
 
echo Date("Y-m-d", strtotime("2013-01-31 +3 Month -1 Day")); // 2013-04-30

echo Date("Y-m-d", strtotime("2013-12-31 -1 Month -1 Day")); // 2013-11-30

echo Date("Y-m-d", strtotime("2013-12-31 -2 Month")); // 2013-10-31

echo Date("Y-m-d", strtotime("2013-12-31 -3 Month")); // 2013-10-01

echo Date("Y-m-d", strtotime("2013-12-31 -3 Month -1 Day")); // 2013-09-30