duanlidi1051 2011-12-19 20:58
浏览 16
已采纳

允许在PHP日期中忽略几天或几个月

I have date field in my MySQL DB and three fields (yyyy-mm-dd) in my PHP form. The user would set a complete date but can also set a "yyyy-mm" or "yyyy" date. In MySQL everything is going right, if the user only set the year, it store "yyyy-00-00". So as there is no 00 day in a month and no 00 month in a year, it acts like a "NULL" day or month.

But, when i want to display de date back to the user, using th date_format PHP function, if the date is "2012-00-00", it display "2011-12-30".

How can I easily (not using have_day and have_month columns in the db) handled this behaviour?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongyi2159 2011-12-19 21:10
    关注

    Your case is unusual. You cannot use DATE class to format dates. Try treating date as literal string.

    if (strstr($date_returned,'-00-00'))
    {
        echo  str_replace('-00-00','',$date_returned).'-00-00';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器