How to convert date from one format to another?

前端 未结 4 937
温柔的废话
温柔的废话 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 12:49

    For a more general approach, you can always dump your current format to a string, like how you have it, and use string operations to substring and reorganize. I know for a fact that MySQL accepts string values for DATETIME fields.

    $day = substr($input, 0, 2);
    $month = substr($input, 2, 3);
    switch($month){
        case "Jan":
            $month = "01";
            break;
        ...
    }
    

提交回复
热议问题