Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Storing credit card expiration date

1 view
Skip to first unread message

Sean Sankey

unread,
Jan 15, 2003, 9:59:07 PM1/15/03
to
I need to store just the month year for a credit card expiration date. How
can I enforce this at the table level by using a datetime datatype set to
just month year? Should I be using a nvarchar datatype and storing just
"0103" as a text value and then figure out how to validate it in the client
application?

Somebody must have encountered this before... and there's probably a
make-shift/better/best way of doing this...

Thanks,
Sean


Steve Kass

unread,
Jan 16, 2003, 12:42:48 AM1/16/03
to
Sean,

Here's a check constraint you can use, along with a suggestion
that having a column with the month after the mm/yy might also
be handy for verifying that a card is still valid.

create table CardExp (
i int identity(1,1),
expMonth datetime check (datepart(day,expMonth) = 1),
goodIfBefore as dateAdd(month,1,expMonth)
)

insert into CardExp(expMonth) values ('19990201')
insert into CardExp(expMonth) values ('20040918')
insert into CardExp(expMonth) values ('20030501')
select * from CardExp
go

drop table CardExp

Steve Kass
Drew University

Jaywant Dharwadkar

unread,
Jan 16, 2003, 2:27:15 AM1/16/03
to
Please take a look at SQL Server FAQ website. You might find some of
your questions answered here.

http://vyaskn.tripod.com/programming_faq.htm

<b>How to get rid of the time part from the date returned by GETDATE
function?
</b>

We have to use the CONVERT function to strip the time off the date.
Any of the following commands will do this:

SELECT CONVERT(char,GETDATE(),101)
SELECT CONVERT(char,GETDATE(),102)
SELECT CONVERT(char,GETDATE(),103)
SELECT CONVERT(char,GETDATE(),1)

See SQL Server Books Online for more information on CONVERT function.

"Sean Sankey" <ssa...@adelphia.net> wrote in message news:<%dpV9.8135$Fj2.4...@news2.news.adelphia.net>...

0 new messages