将1天添加到DATETIME格式值 [英] adding 1 day to a DATETIME format value

查看:105
本文介绍了将1天添加到DATETIME格式值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我想为DATETIME格式化的变量添加1天:

In certain situations I want to add 1 day to the value of my DATETIME formatted variable:

$start_date = date('Y-m-d H:i:s', strtotime("{$_GET['start_hours']}:{$_GET['start_minutes']} {$_GET['start_ampm']}"));

最好的方法是什么?

推荐答案

如果要在PHP中执行此操作:

If you want to do this in PHP:

// replace time() with the time stamp you want to add one day to
$startDate = time();
date('Y-m-d H:i:s', strtotime('+1 day', $startDate));

如果要在MySQL中添加日期:

If you want to add the date in MySQL:

-- replace CURRENT_DATE with the date you want to add one day to
SELECT DATE_ADD(CURRENT_DATE, INTERVAL 1 DAY);

这篇关于将1天添加到DATETIME格式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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