Connecting Tech Pros Worldwide Help | Site Map

sql queries

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 19th, 2008, 06:25 PM
mo/-/sin
Guest
 
Posts: n/a
Default sql queries

hi.
i want to make a table in sql server 2005 and i want that there should
be two columns one if date and other for time......
i want that date column should show only date but not time and the
time column should show only time not date......
i tried this but when i enter only time it shows date also n that is
1900-01-01 and when i enter date it shows time also i.e 00:00:00...

  #2  
Old August 19th, 2008, 09:25 PM
Erland Sommarskog
Guest
 
Posts: n/a
Default Re: sql queries

mo/-/sin (Ri.mohsin@gmail.com) writes:
Quote:
i want to make a table in sql server 2005 and i want that there should
be two columns one if date and other for time......
i want that date column should show only date but not time and the
time column should show only time not date......
i tried this but when i enter only time it shows date also n that is
1900-01-01 and when i enter date it shows time also i.e 00:00:00...
On SQL 2005 there are no date-only or time-only data types. However,
SQL 2008, just released have this.

In SQL 2005, the best you can do is:

datecol datetime CHECK (datecol = convert(char(8), datecol, 112)),
timecol datetime CHECK (convert(char(8), timecol, 112) = '19000101')

This constrains the time porttion for the date column to midnight, and
the date portion for the time column to 1900-01-01. The reason I picked
this date is that this is the "zero date" in SQL Server.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.