Sportalcraft Sportalcraft - 5 months ago 17
SQL Question

Access 2010 SQL Query

I need a query that return values from the beginning of the current month until today.

For example :

SELECT *
FROM Orders
WHERE OrderDate BETWEEN #1/6/2016# AND Now();


But I need this query to work not just this month...

Answer

If you have a given date, you could use the DATESERIAL() function to grab the first day of a given month :

SELECT *
  FROM Orders
 WHERE OrderDate BETWEEN DATESERIAL(Year(YourDate), Month(YourDate), 1) AND NOW()

If you were able to explicitly pass in the month and year, you could do that as well :

WHERE OrderDate BETWEEN DATESERIAL(2016, 6, 1) AND NOW()
Comments