Loading...

PHP的日期加減運算

Temperature: 0 °C

ChungChung
author_tools

在2004-01-08再加上15天 = 2004-01-23


$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months,$days+15,$years));


在2004-01-08再加上6個月 = 2004-07-08

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months+6,$days,$years));


在2004-01-08再加上2年 = 2006-01-08

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months,$days,$years+2));


在2004-01-08再減15天 = 2003-12-24

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months,$days-15,$years));


在2004-01-08再減6個月 = 2003-07-08

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months-6,$days,$years));


在2004-01-08再減2年 = 2002-01-08

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months,$days,$years-2));


select *
FROM commercial
WHERE up_Date = NOW()

https://innstory.com/story-PHP的日期加減運算-94
寫程式筆記

Prev
 瀏覽器升級ie9後FCKEditor無法使用對話框解決方法

Next
使FCKeditor所上傳的圖檔檔名亂數化 

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

地圖故事

地圖故事

map 一切都從第一張畫布開始... Innstory裡原先已有寫故事的功能,接著我把故事裡頭的照片...

動態時報?

動態時報?

dsc5 抓meta value的功能雖然還不是很完整... 但一些網站的meta value 已經...

javascript 底下使用 htmlspecialchars

javascript 底下使...

pexelsphoto Javascript中使用一個函數達到PHP的htmlspecialchar...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format