?
Solved

query syntax

Posted on 2013-06-02
4
Medium Priority
?
116 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
Suggested Courses

777 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