Quote:
|
Originally Posted by Datanalysis
example when I create a table how when I define datetime as datatype is there a way to define it so only date shows and never time? i need it for a birthday field.
CREATE TABLE Customer
(
Cust_ID int Identity (1000,1) primary key NOT NULL,
Cust_Birthday datetime NULL,
);
|
To answer "is there a way to define it so only date shows", generally, no. Data types say what data can go in there, not how it looks.
You can, however, force the time to be something reliable like 00:00:00 by adding a check constraint that HOUR(Cust_Birthday) = 0 AND MINUTE(Cust_Birthday) = 0 AND SECOND(Cust_Birthday) = 0. That will simplify your date arithmetic because you will be guaranteed that any difference between two dates is an integral number of days.
Further, you can create a query that only retrieves the date and that formats it pretty well however you like.
Rudy's web site has a few examples of e.g. calculating ages.