I have a SQL Server query that I need to return all dates that are less that 90 days from the current. I thought this was quite trivial until the result set returned was completely wrong. Here's the query.
SELECT new_HwWarrantyEndDate
FROM TABLE
WHERE new_HwWarrantyEndDate IS NOT null
AND DATEDIFF(day,GETDATE(),new_HwWarrantyEndDate) <= 90;
Here are some of the results:
new_HwWarrantyEndDate
---------------------
2010-07-11
2012-12-09
2011-02-12
2012-12-09
2007-12-31
2007-12-31
2007-12-31
2007-12-31
How could this function return dates from years previous?
I have another issue.Why would a query such as:
SELECT DATEDIFF(day,GETDATE(),new_HwWarrantyEndDate) AS DateDiff
FROM TABLE
WHERE Diffdate IS NOT null;
Complain specifically DateDiff is not a valid column when I try and process the resultset ie:
result_set = stmt.executeQuery(query);
Date s;
if(!result_set.next()) {
System.out.println("Null set");
}
while(result_set.next()){
s = result_set.getDate("DateDiff");
System.out.println(s);
}
Thanks I don't have much experience with SQL Server. Any guidance would help.