用PHP减去1天 [英] Subtract 1 day with PHP

查看:179
本文介绍了用PHP减去1天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的Drupal CMS中取出一个日期对象,减去一天并打印出两个日期.这就是我所拥有的

I'm trying to take a date object that's coming out of my Drupal CMS, subtract one day and print out both dates. Here's what I have

$date_raw = $messagenode->field_message_date[0]['value'];

print($date_raw);

//this gives me the following string: 2011-04-24T00:00:00

$date_object = date_create($date_raw);

$next_date_object = date_modify($date_object,'-1 day');

print('First Date ' . date_format($date_object,'Y-m-d'));

//this gives me the correctly formatted string '2011-04-24'

print('Next Date ' . date_format($next_date_object,'Y-m-d'));

//this gives me nothing. The output here is always blank

所以我不明白为什么原始日期对象会很好,但是随后我试图创建一个额外的日期对象并通过减去一天来对其进行修改,看来我无法做到这一点.输出总是空白.

So I'm not understanding why the original date object is coming out fine, but then I'm trying to create an additional date object and modify it by subtracting one day and it seems like I can't do that. The output always comes out blank.

推荐答案

您可以尝试:

print('Next Date ' . date('Y-m-d', strtotime('-1 day', strtotime($date_raw))));

这篇关于用PHP减去1天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆