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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.