Convert a date format in PHP

后端 未结 18 2350
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 06:09

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL); however I don\'t know how the date function requires a timestamp, and

18条回答
  •  礼貌的吻别
    2020-11-21 06:54

    $newDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3-$2-$1",$originalDate);
    

    This code works for every date format.

    You can change the order of replacement variables such $3-$1-$2 due to your old date format.

提交回复
热议问题