shmoel
asked on
monthly report, MySQL - DateTime
Hi,
I have my_date field in my table that contains DATETIME format (2004-03-01 17:34:57) for every uploaded document. Now, every month I want to retrieve documents in the range of
2004-currentMonth-01 through 2004-currentMonth-30. So, basicly it's kind of monthly report for current month only beginning with very first day and ending with very last day of the same month.
I could probably specify my date and time every month, changing my WHERE .... condition every month mannually, but I believe there is an automated way of doing it with MySQL Version 4.0.18; and your help is much appreciated.
Thanks.
I have my_date field in my table that contains DATETIME format (2004-03-01 17:34:57) for every uploaded document. Now, every month I want to retrieve documents in the range of
2004-currentMonth-01 through 2004-currentMonth-30. So, basicly it's kind of monthly report for current month only beginning with very first day and ending with very last day of the same month.
I could probably specify my date and time every month, changing my WHERE .... condition every month mannually, but I believe there is an automated way of doing it with MySQL Version 4.0.18; and your help is much appreciated.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Take eicheled's answer and throw in the CURRENT_DATE() or NOW() functions, and you have it.
Suppose that you have:
startDate & endDate DATETIME formated variables for begin and end of mounth:
SELECT * FROM my_table WHERE my_date BETWEEN startDate AND endDate ORDER BY my_date ASC
startDate & endDate DATETIME formated variables for begin and end of mounth:
SELECT * FROM my_table WHERE my_date BETWEEN startDate AND endDate ORDER BY my_date ASC