Computing.Net > Forums > Web Development > echo datetime so as more readable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

echo datetime so as more readable

Reply to Message Icon

Name: martineagle
Date: January 9, 2006 at 05:44:50 Pacific
OS: Win XP Pro
CPU/Ram: 512
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: January 9, 2006 at 08:19:57 Pacific
Reply:

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


0

Response Number 2
Name: Michael J (by mjdamato)
Date: January 9, 2006 at 08:21:28 Pacific
Reply:

Oh yeah, for anything to do with PHP, my first stop is always PHP.net

Great reference site.

Michael J


0

Response Number 3
Name: Laler
Date: January 9, 2006 at 19:55:07 Pacific
Reply:

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));

---
Site of the Day


0

Response Number 4
Name: martineagle
Date: January 10, 2006 at 02:49:01 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


what next after domain? ecommerce web design



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: echo datetime so as more readable

How do I post code? www.computing.net/answers/webdevel/how-do-i-post-code/3416.html

POST method not sending content www.computing.net/answers/webdevel/post-method-not-sending-content/1609.html

Server Side www.computing.net/answers/webdevel/server-side/262.html