Friday, August 21, 2015

find out expired credit cards with MM/YY format

I have a table which stores expiry dates of credit cards
ExpiryDate Varchar(10) --datatype
The dates look like this:
'08/10'
'09/11'
'08/16'
'10/17'
how can i find out if a card's date is expired?

ANS: 

SELECT * from Table where isactive=1 
 AND LEFT(ExpiryDate
 

, 2) >= MONTH(GETDATE())
        AND RIGHT(ExpiryDate
 

, 2) >= RIGHT(YEAR(GETDATE()), 2)

No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...