How to convert date from one format to another?

前端 未结 4 977
温柔的废话
温柔的废话 2021-01-28 12:26

I\'m having the date in this format in a Excel worksheet 03-Dec-10. So its not compatible while inserting it into the database. How to convert the date to the acceptable format?

4条回答
  •  死守一世寂寞
    2021-01-28 13:12

    $input = '03-Dec-10';
    $date = DateTime::createFromFormat('d-M-y', $input);
    echo $date->format('Ymd'); // or possibly 'Y-m-d'
    

    This will output 20101203, which is presumably what you want. If it's not exactly what you are after, have a look here.

    You can also do the reverse:

    $input = '20101203';
    $date = DateTime::createFromFormat('Ymd', $input);
    echo $date->format('d-M-y');
    

提交回复
热议问题