Jump to content

Recommended Posts

Hello -

I have 2 select statements:

1.) select DATE_FORMAT(article_creation_date, '%d/%m/%Y') from t_article_details where article_id = 5000;

2.) SELECT article.article_edition_number, article.article_id, article.article_title, article.article_author_id, author.article_author_name, author.article_author_email, article_text, DATE_FORMAT(article.article_publication_date, '%d/%m/%Y') as article_publication_date, DATE_FORMAT(article.article_creation_date, '%d/%m/%Y') as article_creation_date, article.article_summary FROM t_article_details as article, t_article_author_details as author WHERE ((article_id = '$article_id') and (article.article_author_id = author.article_author_id));

The first gives the desired result: 27/05/2005

+------------------------------------------------+
| DATE_FORMAT(article_creation_date, '%d/%m/%Y') |
+------------------------------------------------+
| 25/07/2005 |
+------------------------------------------------+
1 row in set (0.00 sec)

The second gives an incorrect result: 06/06/2006

$article_creation_date = $row_RS_article_details['article_creation_date'];
echo "article_creation_date: $article_creation_date";

Can someone please explain why?!? It should be the same result in both cases, surely...

Regards,

Neil.
Link to comment
https://forums.phpfreaks.com/topic/11359-strange-select-result/
Share on other sites


That would make sense... But the field has a value... So if I have the following statement:

SELECT article.article_edition_number, article.article_id, article.article_title, article.article_author_id, author.article_author_name, author.article_author_email, article_text, DATE_FORMAT(article.article_publication_date, '%d/%m/%Y') as article_publication_date, DATE_FORMAT(article.article_creation_date, '%d/%m/%Y') as article_creation_date, article.article_summary FROM t_article_details as article, t_article_author_details as author WHERE ((article_id = '$article_id') and (article.article_author_id = author.article_author_id));

... how do I assign "DATE_FORMAT(article.article_creation_date, '%d/%m/%Y') as article_creation_date" to a variable? I thought that I had done this with:

$article_creation_date = $row_RS_article_details['article_creation_date'];
echo "article_creation_date: $article_creation_date";

Regards,

Neil.
Link to comment
https://forums.phpfreaks.com/topic/11359-strange-select-result/#findComment-42631
Share on other sites


Direct selects from the database:

mysql> select article_creation_date from t_article_details where article_id = 5000;
+-----------------------+
| article_creation_date |
+-----------------------+
| 20050725133459 |
+-----------------------+
1 row in set (0.05 sec)

mysql> select DATE_FORMAT(article_creation_date, '%d/%m/%Y') from t_article_details where article_id = 5000;
+------------------------------------------------+
| DATE_FORMAT(article_creation_date, '%d/%m/%Y') |
+------------------------------------------------+
| 25/07/2005 |
+------------------------------------------------+
1 row in set (0.01 sec)

Here, I asign it to a variable:

mysql_select_db($database_db, $db);
$query_RS_article_details = "SELECT article.article_edition_number, article.article_id, article.article_title, article.article_author_id, author.article_author_name, author.article_author_email, article_text, DATE_FORMAT(article.article_publication_date, '%d/%m/%Y') as article_publication_date, DATE_FORMAT(article.article_creation_date, '%d/%m/%Y') as article_creation_date, article.article_summary FROM t_article_details as article, t_article_author_details as author WHERE ((article_id = '$article_id') and (article.article_author_id = author.article_author_id))";
$RS_article_details = mysql_query($query_RS_article_details, $leaderdb) or die(mysql_error());
$row_RS_article_details = mysql_fetch_assoc($RS_article_details);
$totalRows_RS_article_details = mysql_num_rows($RS_article_details);
$article_creation_date = $row_RS_article_details['article_creation_date'];
$article_publication_date = $row_RS_article_details['article_publication_date'];
$article_modification_date = $row_RS_article_details['article_modification_date'];

echo "article_creation_date: $article_creation_date";
echo "article_publication_date: $article_publication_date";
echo "article_modification_date: $article_modification_date";

The output:

article_creation_date: 07/06/2006article_publication_date: 11/04/2020article_modification_date:

Any ideas?

Regards,

Neil.
Link to comment
https://forums.phpfreaks.com/topic/11359-strange-select-result/#findComment-42636
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.