Create a date from Credit Card expire in MMYY format
- by Sophtware
I need to convert a credit card expire field from MMYY to a date field I can use in a MS SQL query so I can compute when credit cards are expiring in the future. Basically, I need to go from MMYY to MM/DD/YYYY, where the day part could just be '01' (the first of the month).
I'm looking for credit cards that are expiring next month from a database. The problem I'm running into is when next month is the first month of the next year.
Here's the code I have for determining expired card:
(CAST(SUBSTRING(CCExpire,3,2) as int) + 2000 < YEAR(GETDATE()))
or
(
(CAST(SUBSTRING(CCExpire,3,2) as int) + 2000 = YEAR(GETDATE()))
AND
(CAST(SUBSTRING(CCExpire,1,2) as int) < MONTH(GETDATE()))
)
And here's the code for cards expiring this month:
(CAST(SUBSTRING(CCExpire,3,2) as int) + 2000 = YEAR(GETDATE()))
AND
(CAST(SUBSTRING(CCExpire,1,2) as int) = MONTH(GETDATE()))
Now I need code for cards expiring next month...