Convert MMDDYYYY to date for PHP

前端 未结 6 723
你的背包
你的背包 2021-01-14 10:46

I have a string with a date which is in this format MMDDYYYY (ie. 01132012, 01142012 etc.)

I need to do something on a page, if that string is 14 days or less from t

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 11:21

    You can use the DateTime class of PHP

    diff($date);
    
      ...
    
      // output the date in format you want
      echo $date->format('d/m/Y');
    ?>
    

    EDIT: I just realized, that your format isn't one supported by php. So you have to use alternate objectbuild.

提交回复
热议问题