As you will see from the comments above then you should really be storing the expiry date in the correct column type - Date, DateTime or DateTime2.
However, assuming you have stored this as a
varchar
then the following code snippet demonstrates how you can still use it in the
DateDiff
function:
DECLARE @badIdea varchar(7) = '05/2016'
DECLARE @extendedDate varchar(10) = SUBSTRING(@badIdea, 4, 4) + '-' + SUBSTRING(@badIdea, 1, 2) + '-01'
SELECT datediff(dd, CAST(@extendedDate AS date), GETDATE())
Or as part of a query it would look like
SELECT datediff(dd, CAST(SUBSTRING(expiry, 4, 4) + '-' + SUBSTRING(expiry, 1, 2) + '-01' AS date), GETDATE())
FROM yourTable
I cannot stress strongly enough that you should really store the data in a Date type on your table!
As the day appears to be unimportant then choose an arbitrary number that will exist for every month e.g. 1, 15 or 28