Question WHERE date smaller than?

jmcbr2002

New member
Joined
Aug 23, 2022
Messages
1
Programming Experience
Beginner
I have a select in C# and I need the WHERE clause to compare if a particular field in the database has a date smaller than today's Date (less (-) 365
 
Show us the relevant code. That's not something we should have to ask for. If you want help with code, show us the code you want help with. Please be sure to format the code appropriately.
 
Unless the OP shows us some LINQ, this is looking to be more of a SQL language question, rather than a C# language question.
 
The concept of "now" and date math varies from database to database, for example:


MySQL:​

SELECT *
FROM Users
WHERE CreatedDate BETWEEN DATE_SUB(NOW(), INTERVAL 365 DAY) AND NOW();

Oracle:​

SELECT *
FROM Users
WHERE CreatedDate BETWEEN SYSDATE - INTERVAL '365' DAY AND SYSDATE;

SQL Server:​

SELECT *
FROM Users
WHERE CreatedDate BETWEEN DATEADD(DAY, -365, GETDATE()) AND GETDATE();

SQLite:​

SELECT *
FROM Users
WHERE CreatedDate BETWEEN DATETIME('now', '-365 days') AND DATETIME('now');

MS Access:​

SELECT *
FROM Users
WHERE CreatedDate BETWEEN DATEADD('d', -365, DATE()) AND DATE();


When asking questions in future please be clear about which technologies and versions you use


Edit: aye carumba - what's a post from aug 22 doing in my recent activity list? Was i looking at the recent activity list? PEBKAC
 
Back
Top Bottom