1

How to Convert 2017-03-01 to March 1st 2017 format in PHP.

 $mark_entry_last_date=$exam_dates['last_date'];

 echo date('M j<\sup>S</\sup> Y', $mark_entry_last_date);

Above code outputs current date only but I need the date value for $mark_entry_last_date. How to get a result like March 1st 2017 for given date using escape characters. ?

Dayz
  • 269
  • 2
  • 12
  • 2
    Use `strtotime()` to `$mark_entry_last_date`, check [here](http://ideone.com/xcBEdU) – Fabio Jan 03 '17 at 06:39
  • 2
    Possible duplicate of [Strtotime() doesn't work with dd/mm/YYYY format](http://stackoverflow.com/questions/2891937/strtotime-doesnt-work-with-dd-mm-yyyy-format) – Abdulla Nilam Jan 03 '17 at 06:43

2 Answers2

4

date function expects second parameter to be timestamp (integer) not string, so you need to use strtotime:

echo date('M j<\s\up>S</\s\up> Y', strtotime($mark_entry_last_date));

Also you need to escape u for sup tag. Since u is format for displaying microseconds.

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
1

Try without tags and use strtotime()

echo date("F jS Y", strtotime("2017-03-01"));  
// output March 1st 2017

For more http://php.net/manual/en/function.strtotime.php

Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44