List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:September 14 1999 11:14am
Subject:Re: How to use the correct Date and Time Functions ( new quiestion )
View as plain text  
On Tue, 1999-09-14 04:45:04 -0500, Manuel Coral A. wrote:
> the question here is very good,  but what happen if,
> for example I need to get a report of all entries of the
> week  in that the date that the user enter is ..?.. , it
> is, for example the date for now is 1999-09-14 and I
> want to get a report of all entries from the las sunday
> to now ( entries to this week ), and tomorrow I will
> want  to get a report from last sunday to tomorrow, and
> so on for the another days... of course, until the next
> sunday, and the same for the next weeks.. has mysql any
> function to do that..?

Yep, it has.  See the fine MySQL Reference Manual, chapter
"7.3.11 Date and time functions".

+-----------------------------------+
| DATE_FORMAT( '1999-09-14', '%W' ) |
+-----------------------------------+
| Tuesday                           |
+-----------------------------------+

+-------------------------+
| WEEKDAY( '1999-09-14' ) |
+-------------------------+
|                       1 |
+-------------------------+

+----------------------------------------------------------------+
| DATE_SUB( '1999-09-14', INTERVAL 1+WEEKDAY('1999-09-14') DAY ) |
+----------------------------------------------------------------+
| 1999-09-12                                                     |
+----------------------------------------------------------------+
--> that's a Sunday.

+----------------------------------------------------------------------------------+
| DATE_FORMAT( DATE_SUB('1999-09-14', INTERVAL 1+WEEKDAY('1999-09-14') DAY), '%W') |
+----------------------------------------------------------------------------------+
| Sunday                                                                           |
+----------------------------------------------------------------------------------+

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
How to use the correct Date and Time Functions ( new quiestion )Manuel Coral A.14 Sep
Re: How to use the correct Date and Time Functions ( new quiestion )Martin Ramsch14 Sep
  • Re: How to use the correct Date and Time Functions ( new quiestion )Manuel Coral A.14 Sep