drgc9632 2014-05-21 15:52
浏览 25

将“2014年5月21日星期三”等日期转换为时间戳

I formated a datepicker with this format : dateFormat: 'DD, d MM, yy'.

Then I have a form,

If user dont choose a date then it will assume the current date in this format: echo date('l, j F, Y - H:i:s'); and save in database.

If user fill the input date, so I want to save in database this filled date.

The problem is, in my database Im getting date like this: 0000-00-00 00:00:00.

Im trying to use strototime to convert date to timestamp but Im not having sucess doing this.

Do you know How we can do this?

<input type="text" class="datepicker"  name="date" value="if(isset($_POST['date'])) echo strtotime($f['date']); else echo date('l, j F, Y - H:i:s'); ?>" />
  • 写回答

2条回答 默认 最新

  • doutan2228 2014-05-21 16:17
    关注

    Convert date like 'Wednesday, 21 May, 2014' to timestamp

    I am not sure, how you are using the input with insert statement.
    But you should have used proper date_format string so that MySQL interprets it as valid datetime string.

    Example:

    select @dt:='Wednesday, 21 May, 2014' dt, 
           str_to_date( @dt, '%W, %d %M, %Y' ) ts;
    

    What I think that you have used a wrong format string. You better use '%W, %d %M, %Y'.

    Example:

    insert 
      into   table_name( timstamp_field )
     values( str_to_date( $date_time_input_by_user, '%W, %d %M, %Y' ) )
    

    And unless this is from user input, you have to use different MySQL format string that matches with PHP date format string ''l, j F, Y - H:i:s''

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题