Skip to content
Advertisement

Convert Date to Day and Month (3 Letters)

I have date of each post stored in date field in db. The format is DD/MM/YYYY (eg : 24/12/2013). Field is VARCHAR(50)

I want to print Day and month in a page (A Blog listing page). ie like “24 DEC” (Doesnt need year)

What’s the best possible way to achieve it

Note : I’m using PHP

Advertisement

Answer

Please start storing dates in Y-m-d format in DATE fields. Your life, and ours, would be much easier.

Until then, use this php solution:

$dt = DateTime::createFromFormat('!d/m/Y', '24/12/2013');
echo strtoupper($dt->format('j M')); # 24 DEC

demo

or mysql solution:

SELECT STR_TO_DATE('24/12/2013','%d/%m/%Y')
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement