Jump to content

[SOLVED] date format


felipeebs

Recommended Posts

is there any faster way to call the result, I mean:

$sql = "SELECT *, date_format(date, '%d/%m/%Y %T') FROM eyetest ORDER BY id DESC";

$query = mysql_query($sql);

while($n = mysql_fetch_assoc($query)){

	echo $n["id"].' | ';
	echo $n["date"].' | ';
	echo $n["date_format(date, '%d/%m/%Y %T')"].'<br />';

	print_r($n);
}

 

prints this:

2 | 2008-06-07 06:08:07 | 07/06/2008 06:08:07
1 | 2008-06-07 06:08:03 | 07/06/2008 06:08:03

 

I had to call $n["$n["date_format(date, '%d/%m/%Y %T')"]

Anything to simplify this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-559770
Share on other sites

I'm sorry for reviving this topic, but I found the query simpler way

with this

$results = mysql_fetch_assoc(mysql_query("SELECT date_format(date, '%M %d %Y %H:%i') as date FROM table"));
print_r($results);

will return

Array
(
    [date] => June 14 2008 14:08
)

 

conclusion:

SQL code "SELECT date_format(column, format)" can receive the keyword "as var", so it do not returns

$results[date_format(date, '%M %d %Y %H:%i')] = ...

but returns

$results[var] = ...

 

 

I'm sorry again, but this may be usefull for someone else.

Link to comment
https://forums.phpfreaks.com/topic/109086-solved-date-format/#findComment-564067
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.