I try to select the Products that has a yearmodel between +1 and -1 the current year. And I only want the Year (ex 2011) not the full date and time.
SELECT ProductName FROM tblProduct WHERE Year BETWEEN
year(getdate()+1) AND year(getdate()-1)
Does not work, but something similar maybe...
ADD_MONTHS() function returns a date with a given number of months added (date plus integer months). A month is defined by the session parameter NLS_CALENDAR. A datetime value or any value that can be implicitly converted to DATE. An integer or any value that can be implicitly converted to an integer.
This is a way to get current financial year using SQL query: DECLARE @FIYear VARCHAR(20) SELECT @FIYear = (CASE WHEN (MONTH(GETDATE())) <= 3 THEN convert(varchar(4), YEAR(GETDATE())-1) + '-' + convert(varchar(4), YEAR(GETDATE())%100)
You can use dateadd function. dateadd(year,1,thedate).
You are adding the 1 to getdate() so you are adding 1 day
SELECT ProductName FROM tblProduct WHERE Year BETWEEN
(year(getdate()) -1) AND (year(getdate()) + 1)
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