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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?