Forum Moderators: coopster

Message Too Old, No Replies

convert a string "20081210" into date.

         

zozzen

8:54 am on Feb 24, 2008 (gmt 0)

10+ Year Member



By using date("Ymd"), we can get a string "20080224",
but how can i convert it back to "Feb 24"?

I tried:
echo date('M ds',strtotime("20081212");

and
echo date('M ds',"20080224");

but it doesn't work.
Sorry to ask this silly question. I've tried to search php manual but still can't get the answer on this.....

PHP_Chimp

11:06 am on Feb 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just tried -

echo date('M d', strtotime('20080224'));

And got 'Feb 24'

<edit>
Strangely I have tried date('M ds' ...) and got 'Feb 2400' so your example with seconds is working for me...so I dont know if what I have above will actually help you as if you have tried and it didnt work then there must be a difference in our systems :(

Just noticed that you are using a different date in each of your examples. So I hope that you noticed that -
echo date('M ds',strtotime("20081212");
will return you 'Dec 1200' as you have asked about the 12th December, not 24th Feb.

[edited by: PHP_Chimp at 11:12 am (utc) on Feb. 24, 2008]

zozzen

4:12 pm on Feb 24, 2008 (gmt 0)

10+ Year Member



Thanks a lot! By using this, i can get "Feb 24th" now.
echo date('M dS', strtotime('20080224'));

I guess i didn't reload the code during the trial and errors process. Next time I'll be more careful.