views:

119

answers:

2

i am creating windows application .In this i have to subtract two dates .i subtract it successfully ,i used TimeSpan to get subtracted value.But when i insert it in SQl Server 2005 db, it inserted with starting date i.e. 1/1/1900 and the calculated difference

which format should i use to insert Time only?

Thanks in advance

A: 

sql date format is yyyy-mm-dd hh:mm:ss for example: 2010-05-07 09:59:59

x2
That format isn't 100% safe for all regional settings. Safe formats are "YYYYMMDD" and "YYYY-MM-DD'T'hh:mm:ss" (where 'T' is literally the letter T between the date and time components), e.g. for your example, '2010-05-07T09:59:59'
Damien_The_Unbeliever
+1  A: 

If you insert just the timespan, it will be interpreted as the time past midnight on 1/1/1900. Perhaps you can convert the timespan to seconds (.TotalSeconds, maybe?) and then store that as an INT to get what you're looking for.

rwmnau