dprq18175 2018-06-27 09:22
浏览 181

输入类型日期,用于设置从数据库中获取的日期

I have database user consist of attribute like name,password,dob and etc. datatype is used to store date is date.while updating, I used to fetch like below

$query="select * from user where email='$user'";
$res=mysqli_query($conn,$query);
$fet=mysqli_fetch_array($res);

<input type="date" id="dob" name="dob" value="<?php if($fet['dob']==00-00-0000){ }else{ echo date($fet['dob']);} ?>">

I want date which is to fetch from database to this above input type date.

  • 写回答

2条回答 默认 最新

  • douzhanhui5662 2018-06-27 09:44
    关注

    EDIT:
    As I understood in comments of my answer, you are storing DATETIME values in your database and not DATE values. Here is how to get a date format from a datetime format using DateTimeclass:

    $dob = new DateTime($fet['dob']);
    $formatted = $dob->format('Y-m-d');
    

    To output it in short syntax in your <input>:

    <?php
    $dob = (new DateTime($fet['dob']))->format('Y-m-d');
    ?>
    <input type="date" id="dob" name="dob" value="<?php echo $dob; ?>">
    

    Issues:
    An <input type="date"> should have a value in the YYYY-MM-DD format.
    The date() function expects a format and a timestamp.
    You did not quote the 00-00-0000 value.

    You won't need to format your date string as its format is right for your input:

    <input type="date" id="dob" name="dob" value="<?php echo $fet['dob']; ?>">
    

    If you need to manipulate dates in PHP I would recommend the DateTime class.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!