0

I have a small events script I wrote to suite my client. The script work perfect but I cannot get the date to display, example:

25 August 2015

My question comes not for the lack of searching Stack Overflow and other resources.

The date format straight from MySQL:

echo  $row['date_start'];  //2015-08-26

How I want it to be:

25 August 2015

And my 3 attempts aren't working as expected. ($DateStartString I get from row $DateStartString = $row['date_start'];)

 echo date_format($row['date_start'],"M/d/YY");
 echo date_format($DateStartString, 'm F Y');
 echo $DateStartString->format('m F Y');
Cœur
  • 37,241
  • 25
  • 195
  • 267
Cavemanharris
  • 185
  • 2
  • 14
  • 2
    important missing step if your using date_format `$date=date_create($row['date_start']);` –  Aug 22 '15 at 11:25
  • ^^ Either do it like Dagon showed it above, or use the OOP style instead: `$dt = new DateTime($row["date_start"]); echo $date->format("m F Y");` (@Dagon btw: you are now in my [profile](http://stackoverflow.com/users/3933332/rizier123?tab=profile) hope you don't mind :) – Rizier123 Aug 22 '15 at 11:28
  • 2
    @Rizier123 should "done vote for you says spider" ;-) –  Aug 22 '15 at 11:31
  • http://codepad.viper-7.com/lIcuHD –  Aug 22 '15 at 11:33
  • try this code: $date = new DateTime($row['date_start']); //d: day, F = Name of Month, Y = Year $formatPattern = 'd F Y'; echo $date->format($formatPattern); See also: http://php.net/manual/de/datetime.format.php Overview of what else you can use as format pattern: http://php.net/manual/en/function.date.php – Frithjof Schaefer Aug 22 '15 at 11:34
  • Thank you Dragon and Rizier123. it works perfect - i had to add time zone out of interest which i did not have. is that a security risk or just a essential item to add ? – Cavemanharris Aug 22 '15 at 12:05

0 Answers0