Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Can you please assist me with making an echo I've written convert my datetime field in MySQL into a more readable format.
I'll post all the code if you need it, but here's the echo'd part...
echo "Written by $data->author and added here: $data->dateadd>";
I'd like the above to show on the resulting page a date like "January 14th, 2006", but at the moment it shows 2006-01-14 21:05:20
One thing that can't change is the format I have for echo'ing the date, meaning I have to keep using '$data->whatever', so please keep that in mind when you're thinking of a solution.
I've had a look at the MySQL site and other suggestions on the web but none of them seem to work for me. Hopefully someone here can shed the light I need.
Thanks in advance,
Martin

See the date function here: http://us3.php.net/manual/en/function.date.php
date ( string format [, int timestamp] )
Just use your returned date value as the timestamp. For example to get the format January 1, 2006 you would do this:
date ( "F j, Y", $data->dateadd )
Michael J

Michael, I think date() will use UNIX timestamp, so I'm not sure if putting a data with MySQL timestamp column type will work.
I think it should be like this:
date ("F j, Y", strtotime ($mysqltimestamp));

Fantastic Laler, that's the key I needed.
I've been playing around with Michael's code for a while and not getting very far but yours has worked a treat.
Thanks to both of you for your assistance.

![]() |
what next after domain?
|
ecommerce web design
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |