duanguangwang5829 2018-05-21 10:09 采纳率: 0%
浏览 53
已采纳

是否有可能将像7-Feb这样的字符串转换为当前年份的yyyy-mm-dd与php [复制]

This question already has an answer here:

I have a SQL table imported from an CSV excel sheet with PHP. The import wasn't optimized to detect dates and create column type Date while creating the table which now has a 'varchar' column with dates like 7-Feb, 8-Feb etc. But now I do not have the excel sheet to change the format there and re import. So I need to convert the data in the imported database from the 7-Feb format to yyyy-mm-dd for all rows. The reason being, if I change the column type from 'Varchar' to 'Date'now, the string is not recognized and becomes 0000-00-00. And I lose my information. So I have to change the varchar string to date format before changing the column type.

Is this possible with php ?

</div>
  • 写回答

1条回答 默认 最新

  • dongmi1872 2018-05-21 10:12
    关注
    <?php
    $dateSet = array('7-Feb','8-Feb','9-Feb-2018');
    foreach($dateSet as $date){
        $newDate = date('Y-m-d',strtotime($date));
        var_dump($newDate);
    }
    

    Should do it nicely

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题