Reputation: 11
I am trying to convert a Julian date to Gregorian Date (MM/DD/YYYY
) and compare it with a normal date:
WHERE CONVERT(VARCHAR, dbo.ConvertToGregDate(ExpDate), 101) < '04/01/2017'
This returns all the dates before 04/01 disregarding the year (e.g. the result will not include 04/02/2016 or 05/01/2016).
Is there anything different I should do here?
Upvotes: 1
Views: 750
Reputation: 70658
The problem is that you are comparing strings. If you are gonna do that, than you should use a date format that can be compared that way:
where convert(varchar(8), dbo.converttogregdate(ExpDate), 112) < '20170401'
Or better yet, don't convert your result to string at all:
where dbo.converttogregdate(ExpDate) < '20170401'
Upvotes: 2