-2

To store only time from DateTime into SQL Server 2005. I am using vs.net 2010 and SQL Server 2005

Like this

MyCurrent   DataType 
id          int
EnterDate   DateTime
Date        string
Time        string

// I want to like this STORE [Future out put]
id  ....  EnterDate             Date         Time
1   ....  4/11/2011 10:25:00   4/11/2011     10:25:00 
2   ....  4/11/2011 10:32:10   4/11/2011     10:32:10 
3   ....  4/11/2011 10:41:37   4/11/2011     10:41:37 

So how to store only time value and how define datatype in SQL Server?

Jig12
  • 2,977
  • 4
  • 23
  • 28
  • 1
    there is a lot tuttorial on web why you dont check and effort on it? – Mustafa Ekici Nov 04 '11 at 07:31
  • SQL Server 2005 does **not** have a "time-only" datatype yet - you need to upgrade to SQL Server **2008** which introduces the `TIME` datatype for this exact purpose – marc_s Nov 04 '11 at 07:48
  • This is not a good idea at all because it violates the rule of good normalization of database. I think you could just store it together and perform separation during selects. – Allan Chua Nov 04 '11 at 08:25

2 Answers2

2

You can get Only time like this

Select CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond

Refer Sql server DateTime for more

0

I guess that you want to have three columns, one with datetime stamp, one with date and one with time only. if thats the case then

SELECT DATEPART(dd/mm/yyyy,EnterDate) AS Date
from table

this will get you all the dates from date time stamp, you can accomodate this in your insert query

SELECT DATEPART(hh:mm:ss,EnterDate) AS Time
from table
Zohaib
  • 7,026
  • 3
  • 26
  • 35
  • 5
    Just as a friendly suggestion, your answer would be a lot easier to read (and look more professional in general) if you used "you" and "your" instead of "u" and "ur". – Jon Skeet Nov 04 '11 at 07:37
  • @JonSkeet agreed, will definitely keep this in mind... – Zohaib Nov 04 '11 at 07:40