2021年3月13日星期六

Display date with ordinal suffix in PHP

I am currently displaying date in my php code like below

$date = $news_row['date'];  $newDate = date("l M d Y", strtotime($date));  

its giving me output like

Monday Mar 08 2021

Instead I want output like

Monday Mar 08th 2021

I have found function

function ordinal($number) {      $ends = array('th','st','nd','rd','th','th','th','th','th','th');      if ((($number % 100) >= 11) && (($number%100) <= 13))          return $number. 'th';      else          return $number. $ends[$number % 10];  }  

on this answer

But I am not getting idea how I can use it with my date format. Let me know if anyone here can help me for do it.

Thanks a lot!

https://stackoverflow.com/questions/66620609/display-date-with-ordinal-suffix-in-php March 14, 2021 at 10:44AM

没有评论:

发表评论