0

I have date in following format (Y-m-d) as 2010-11-24, need to convert it to
1) 24 Nov, 2010
2) 24_Nov_2010

Help appreciated, thanks.

4 Answers 4

2
$oDate = new DateTime('2010-11-24');
echo $oDate->format('d M, Y') . "\n";
echo $oDate->format('d_M_Y') . "\n";
Sign up to request clarification or add additional context in comments.

Comments

1
  1. (d M, Y)
  2. (d_M_Y)

So, something like

date("d M, Y");

Will output todays date:

24 Nov, 2010

Edit: I may have read your question incorrectly. Can you please clarify if this is what you want? Or you wanted to convert the 24-11-2010 into the above formats?

If the latter if what you were seeking, you can simply utilise the strtotime function:

date("d M, Y", strtotime("2010-11-24"));

1 Comment

I need to convert 2010-11-24 or any other date, but in format YYYY-MM-DD (which is returned from Database) to above mentioned format.
1

Most simple, you can use strtotime() to convert 2010-11-24 into date, and use date() to get seperate pieces(Y,m,D) and convert them to whatever format you want.

Please refer this link: http://php.net/manual/en/function.strtotime.php http://php.net/manual/en/function.date.php

Comments

1
$d1 = "2010-11-24";

echo date("d M, Y", strtotime($d1));   // 24 Nov, 2010
echo date("d_M_Y", strtotime($d1));    // 24_Nov_2010

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.