2017-04-17 13 views
-2

我有兩個帶日期數據類型的變量($ deadline和$ reported)。如何在查找兩個日期的差異時顯示負整數

例如:$期限=「2017年4月17日」和$報道=「2017年4月16日」

然後,我使用的strtotime()來改變日期數據類型爲整數數據類型。

當我減去$報價截止日期時,我總是得到正數。

如何讓它顯示負數或正數取決於結果?

enter image description here

+1

檢查[問]。顯示一些代碼。 – domsson

+1

因爲'$截止 - $報告'是一個正數。 $報告 - $截止日期將是一個負數。回覆數字,以便你可以看到你的數學。 – aynber

+0

爲了正確比較和格式化,請查看[這裏](http://stackoverflow.com/questions/15421132/why-does-datetime-days-always-returns-a-positive-number)和[here](http:/ /stackoverflow.com/questions/21557958/datetime-class-how-to-deal-with-negative-date-interval)。 – aynber

回答

0

因爲你減去由更少數量較多,您總能獲得一個正數。儘量減去截止日期報告,並會看到一個負數。

+0

我想知道哪些報告通過了截止日期或沒有... –

+0

您可以使用碳來做到這一點。 http://carbon.nesbot.com/docs/#api-comparison –

相關問題