Converting date From one format to another

前端 未结 4 1387
暗喜
暗喜 2021-01-15 05:21

iam having the date format stored in database as \"20100723\"(YYYYMMDD) and how do i convert it into \"23-JUL-2010\"

4条回答
  •  不知归路
    2021-01-15 05:31

    Use PHP's strtotime() function, it recognizes the date format in the string and converts it into a Unix timestamp.

    $time = strtotime("20100723"); // 1279836000
    

    Then just use date() to convert it back into another string format

    echo date("d-M-Y", $time); // 23-Jul-2010
    

    Note that you would have to use strtoupper() to make "Jul" upper-case

提交回复
热议问题