Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query syntax

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

636 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