Convert string to MMYY Date

  • I am having difficulty converting a string value which represents MMYY into a Date format.

    Assume my string value is 0309 (i.e a credit card expiration date being stored as a string).

    I need that converted into a date format, so that I can filter as if it were a date. ( < 03/09 or < 03/31/09)

    Any suggestions will be appreciated.

    Doug P.

  • You could do something like this...

    Select dateadd(m,1,cast(STUFF('0309',3,0,'/01/') as datetime))-1

    Just replace the '0309' with your field name.

  • Thank you so much. That works perfectly. I was not aware of the STUFF command. I can think of several uses for that.

    Thanks again,

    Doug P.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply