I am trying to write a query to select all records from users
table where User_DateCreated
(datetime field) is >= 3 months from today.
Any ideas?
In SQL Server, you can use the DATEADD() function to get last 3 months (or n months) records.
Instead of approximating the "current" date by selecting the MAX(date) the code could reference CAST(GETDATE() as DATE) to access the system datetime and cast it as type DATE. where [date] > dateadd(month, -6, cast(getdate() as date));
If you need to select rows from a MySQL database' table in a date range, you need to use a command like this: SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01'; Of course you need to change: table.
SELECT * FROM users WHERE user_datecreated >= NOW() - INTERVAL 3 MONTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With