Link to home
Start Free TrialLog in
Avatar of Sim1980
Sim1980

asked on

How to pull MySQL records based on Date in MM/YYYY format

Hi all.

I have an Excel 2007 file that pulls data from a MySQL database.

The fields it pulls are: Name, Count(Type) and the criteria is the CreateDate field which is a datetime datatype which is stored in this format: YYYY-MM-DD HH:MM:SS.

My Excel has 4 parameters: Month1, Year1, Month2 and Year2 (cells B1, D1, B2 and D2).

So the query would be something like:

"SELECT Name,Count(Type)  FROM DataEntry INNER JOIN Users On DataEntry.UserID = Users.UserID WHERE Type = 1 AND CreateDate >= '" & CONCATENATE(B1, "/1/", D1) & "' AND CreateDate <= '" & CONCATENATE(B2, "/1/", D2) & "' GROUP BY Name"

Open in new window


As you can see I am stuck because I don't know how to do the last day of the month since some months end on 31, 30, 28 or 29 if it's a leap year. So I thought maybe I can do it if I format the CreateDate field as MM/YYYY and then concatenate my Excel cells as D1/B1 and D2/B2.

Any help would be appreciated.

Thank you in advance!
SOLUTION
Avatar of lludden
lludden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial