【问题标题】:how to get next month's date and it's not related to current month date in MySQL如何获取下个月的日期,它与 MySQL 中的当前月份日期无关
【发布时间】:2017-08-07 08:59:42
【问题描述】:

我的表中有三列,未来 3 个月,例如 fistdate(下个月)、secondate(+2 下个月)和thirdate(+3 下个月),它们是 DATE 类型。我想将我的日期保存如下 09/09/2017、09/10/2017 和 09/11/2017,当前月份是 07/08/2017 及以上 3 个日期与当前月份日期无关,例如 07/08/ 2017

我尝试过以下代码,但它与当前月份有关

$date1 = date('Y-m-d', strtotime('+1 month'));
    $date2 = date('Y-m-d', strtotime('+2 month'));
    $date3 = date('Y-m-d', strtotime('+3 month'));

     $install = array(
        "invoiceid"              =>$this->input->post('salesInvoiceno', TRUE),
        "fistdate"               =>$date1,
        "secondate"              =>$date2,
        "thirdate"               =>$date3
    );

【问题讨论】:

  • 您好,欢迎来到 Stackoverflow。虽然很高兴你告诉我们你想做什么,但你并没有真正问过问题。请查看stackoverflow.com/help/how-to-ask 并编辑您的问题。另外,请确保您知道 stackoverflow 是为了帮助您,而不是为您编写代码。向我们展示您的尝试,与我们分享您的想法。没有人会为你写代码。
  • 您不想以 RDBMS 预期之外的任何格式存储您的日期。您将数据存储与数据显示混淆了。

标签: php mysql codeigniter


【解决方案1】:

$time = strtotime("2010-08-06");$date1 = date('Y-m-d', strtotime('+1 月',$time));$date2 = date('Y-m-d ', strtotime('+2 月',$time));$date3 = date('Y-m-d', strtotime('+3 月',$time));echo $date1.' '.$date2.' '.$date3;

【讨论】:

  • 谢谢@user3564960
  • 兄弟我做了一点改变,它的工作方式如下: $time = strtotime(date('Y-m-09',time())); //strtotime("2010-08-06"); $date1 = date('Y-m-d', strtotime('+1 月',$time)); $date2 = date('Y-m-d', strtotime('+2 月',$time)); $date3 = date('Y-m-d', strtotime('+3 月',$time));回声 $date1。 '.$date2.' '.$date3;
猜你喜欢
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多