Create a date from Credit Card expire in MMYY format

Posted by Sophtware on Stack Overflow See other posts from Stack Overflow or by Sophtware
Published on 2011-03-10T15:47:20Z Indexed on 2011/03/10 16:10 UTC
Read the original article Hit count: 217

Filed under:
|

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...

© Stack Overflow or respective owner

Related posts about sql

Related posts about query