Solved

query syntax

Posted on 2013-06-02
4
115 Views
Last Modified: 2013-06-10
How do I proper write the following:

This works:
SELECT date_format(value,'%a %c/%e') AS end_date FROM....

Open in new window

This does not:

SELECT magentocatalog_category_entity_datetime.date_format(value,'%a %c/%e') AS end_date FROM...

Open in new window


How do I write the second code example the correct way?
0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39214772
"Works" or "does not" isn't very revealing.  Please complete the SSCCE and show us some code we can copy and experiment with.  You might include a CREATE TEMPORARY TABLE statement and load some data into the table so we can copy the example, install it on our servers and run the queries.  Then we can show you how to get MySQL to reveal the error messages and when we see the messages we can show you how to find the solutions in the MySQL online documentation.

I'm going to take a guess on this one... but something we can test with will almost certainly get you a better response, faster.

SELECT 
DATE_FORMAT(magentocatalog_category_entity_datetime.value,'%a %c/%e') AS end_date 
FROM magentocatalog_category_entity_datetime

Open in new window

0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39215089
date_format() is a MySQL function, and functions require the parameters inside the parentheses that follow the function. (Just like Ray has used above.)

so when you see something like this:
SELECT date_format(value,'%a %c/%e')

the first parameter: "value" is where you would include the field
the second parameter is the required format pattern - some good examples of this at:
http://www.dan.co.uk/mysql-date-format/

:) It did not work because adding ".date_format(value,'%a %c/%e')" to the end of the field isn't the way to use functions in SQL.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39215876
Some man page refs...
http://dev.mysql.com/doc/refman/5.0/en/function-resolution.html
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

'%a %c/%e' should be expected to yield something like Mon 6/6 today.  In the other questions where the formatted date was used in an ORDER BY clause, the results of the ordering may be counterintuitive, since Friday would come before Monday and Thursday would come before Tuesday, etc.  A more useful ORDER BY would be to use the ISO-8601 DATETIME string.  This article shows how you use that.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

HTH, ~Ray
0
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39216228
Might not be a bad idea to use alias in your names to shorten the query.

SELECT
DATE_FORMAT(`mced`.`value`,'%a %c/%e') AS 'end_date'
FROM magentocatalog_category_entity_datetime mced


Note: value would be the column name.

IE: `mced`.`end_date`
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question