Convert a date format in PHP

后端 未结 18 2715
爱一瞬间的悲伤
爱一瞬间的悲伤 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:37

    Use strtotime() and date():

    $originalDate = "2010-03-21";
    $newDate = date("d-m-Y", strtotime($originalDate));
    

    (See the strtotime and date documentation on the PHP site.)

    Note that this was a quick solution to the original question. For more extensive conversions, you should really be using the DateTime class to parse and format :-)

提交回复
热议问题