views:

35

answers:

1

i using MySQL Query for my task. And I interested using Date and time function. can i use DAY(), WEEK(), and YEAR() at one query?

SELECT Object 
  FROM table 
 WHERE DAY(date) BETWEEN 1 AND 7 
GROUP BY WEEK(date, 1), YEAR(date)

i want do this bcoz i'm worry if sometimes my program have an error because of the date setting and not recognize some date.please give me an input.

+1  A: 

Yes, you can use them all in a single query.

The only disadvantage I can think of is that using any of the DAY, WEEK or YEAR functions won't be able to use the index on the column the function is applied to, assuming one is present.

If you're having issues relating to date formatting, you should get familiar with:

OMG Ponies
+1: concise, and answered the question perfectly! ;)
p.campbell
@p.campbell: I don't really know what else to say. The question has to be more complicated than that, right?
OMG Ponies
what is the advantage if i use all? whether with this i have a limitation?
klox
@OMG: i'm just worry if sometimes my program not recognize some date at some year.
klox
@klox: If the issue(s) you're experiencing were more clear, we might be able to help more. I added links to documentation for date formatting that might help.
OMG Ponies