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

清除網頁暫存(no cache)

清除網頁暫存(no cach...

pexelsphoto5 在製作專案時,有沒有試過JS 或 CSS 明明就已經更新了~ 但頁面卻像鬼...

Responsive Web Design使用CSS3的Media Queries進行自適應網頁設計

Responsive Web...

智慧型手持裝置(手機、平板)已是非常普及的日常生活必需品。 所以現在,在開發系統時客戶都會詢問是否支...

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

瀏覽器升級ie9後FCKEd...

原文網址:http://ecshop.tw/bbs/archiver/tid.html 升級到 IE...

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