Forum Moderators: coopster

Message Too Old, No Replies

Just a small problem with date and time!

         

toltec75

10:06 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



Hi!
So I have date and time stored in MySQL database in format YYYY-MM-DD hh:mm:ss!

How do I get it out with PHP to look nice and neat in format such as: DD, MM, YYYY. hh:mm:ss

I tried with a select date_format function but it didn`t work out and I really don`t wanna crack my head with this, so if anyone out there knows this I`d be thankful!

dreamcatcher

10:35 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DATE_FORMAT should do the trick.

$query = mysql_query("SELECT DATE_FORMAT(rowname, '%d,%m,%Y %h:%i:%s') as time_string FROM blah blah...");

$row = mysql_fetch_object($query);

echo $row->time_string;

toltec75

10:53 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



Thanx man!

You didn`t have to write the whole stuff!

The date_format function itself would do fine but thanx again ;).

g1smd

7:49 am on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why not leave it as 2004-08-28 as that is easy to read? That is an international standard (ISO 8601) adopted in all Western and many other countries, and an Internet Standard (RFC 3339).

Writing 09/01/2004 means September 1st in the US and Candada, but means 9th January to Europeans and many others; whereas 2004-09-01 always means 2004 September 01 everywhere on the planet.

You will see a large number of websites already use the latter format for that very reason.

[edited by: g1smd at 7:51 am (utc) on Aug. 28, 2004]

dreamcatcher

7:50 am on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You didn`t have to write the whole stuff!

LOL! No problem. I thought it best to write the syntax in case anyone else wanted to use it.

g1smd

7:56 am on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The forum is browsed by thousands of people per day. Many might be after the same information. Posting a full example is good for those people!

toltec75

9:31 pm on Aug 28, 2004 (gmt 0)

10+ Year Member



Why not leave it as 2004-08-28 as that is easy to read? That is an international standard (ISO 8601) adopted in all Western and many other countries, and an Internet Standard (RFC 3339).
Writing 09/01/2004 means September 1st in the US and Candada, but means 9th January to Europeans and many others; whereas 2004-09-01 always means 2004 September 01 everywhere on the planet.

You will see a large number of websites already use the latter format for that very reason.

Hmmm, maybe you`re right but I`m from Croatia and this generally goes dd-mm-yyyy here.

The guy who wrote the code (dreamcatcher) used mysql_fetch_object function! Can date_format be used with mysql_fetch_array or ...fetch_row for instance.

I tried with those and could`t get it to work!
What I wanna do is to get the date and time with some other info from the database with the same query.

Can it be done and how?

ergophobe

10:10 pm on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, it can be done with mysql_fetch_array, in which case


echo $row->time_string;

becomes


echo $row['time_string'];

dreamcatcher

10:38 pm on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, it can be used with mysql_fetch_array(). Thanks Tom.

$row = mysql_fetch_object($query);

would need to changing to to:

$row = mysql_fetch_array($query);

or if you are getting multiple rows:

while ($row = mysql_fetch_array($query))

{

//code

}

:)

toltec75

10:47 pm on Aug 28, 2004 (gmt 0)

10+ Year Member



Thanx guys!

I guess I didn`t figure out that I have to put "time_string" in the brackets instead of the column name as it is usually done!

I`m into PHP for about something more than 15 days but I see you guys rock! I definitely know where to turn for help! ;)

g1smd

11:47 pm on Aug 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I just ran some pages through the HTML validator at [validator.w3.org...] and guess what the tip of the day was:

Tip Of The Day: Use international date format

which linked to: [w3.org...]

toltec75

12:23 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



I just ran some pages through the HTML validator at [validator.w3.org...] and guess what the tip of the day was:
Tip Of The Day: Use international date format

which linked to: [w3.org...]

Hahahaha :) I`ll check it out!