一个月差距计算 [英] One month gap calculation
问题描述
我正在从数据库中找到应该在30天之后的日期。
I am trying to find the date from the database which should be exactly 30 days from now.
我想从数据库中检索日期,这个日期是 DateTime
格式。使用 strtotime()
将其更改为时间戳。将其提供给 date()
并检索 m
和 i
然后做本地计算,以确定它是否不太恰恰三十天。
I want to retrieve the date from the database which is DateTime
format. change this to timestamp with strtotime()
. feed this to date()
and retrieve the m
and i
and then do local calculation to find out if its less exactly thirty days.
我想知道是否有任何直接和简单的过程来做到这一点。
I want to know if there is any straight forward and easy procedure to do this.
推荐答案
尝试这样:
$date_formatted = date('Y-m-d H:i:s', strtotime($val->time));
要检索 m
或 i
或两者都尝试这样:
To retrieve the m
or i
or both, try this :
$v = date('Y-m-d H:i:s'); //test it with now.
$date_formatted = date('m i', strtotime($v));
要从数据库中查找30天之内的日期,您可以尝试以下方式:
For find date from database that exactly 30 days from now you can try this:
$date_formatted = date('Y-m-d H:i:s', strtotime(' +30 day'));
这篇关于一个月差距计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!