.NETGURU
Storing only timepart in Sql server datetime
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

M O J O
Hi,

How do I store only the time part in a sql server datetime field?

I've tried using ....

Params.Add("@MyField", SqlDbType.DateTime, DateTime.Parse("00:05:00"))

.... but it stores this value "01-09-2004 00:05:00".

I want to store "00:05:00".

Any idea???

Thanks!!!

M O J O

Reply to this message...
 
    
Cowboy (Gregory A. Beamer) - MVP (VIP)
Currently, there is no way to do it in this type of field. Even if you set
everything to 0 plus time, you will have a date portion.

In SQL 2005, you can create a UDT, but in SQL 2000, you are pretty much
stuck with setting up a character data type for the time portion only.
Eventually, you MAY have a time data type, but it is not going to be in the
initial 2005 release (for understandable reasons, BTW).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"M O J O" wrote:

[Original message clipped]

Reply to this message...
 
    
M O J O
Hi Grogory,

I'm doing this already today, but with Delphi. Now I'm using VB.Net and want
to do the same.

I'm using a DateTime field in MS SQL 2000, and by using Delphi's Frac method
(eg. Frac(SomeDateTimeVar)), it is stored in SQL server only showing the
time (when running a query).

I'm not looking for a Time field in SQL, I only want to store the Time in a
datetime.

M O J O

"Cowboy (Gregory A. Beamer) - MVP" <Click here to reveal e-mail addressamM> skrev
i en meddelelse news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Kevin Yu [MSFT] (VIP)
Hi MOJO,

It seems that there is no Time field in SQL server. Could we just save
DateTime in SQL server and only use Time and ignore the Date value?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Reply to this message...
 
 
System.Data.SqlDbType
System.DateTime




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification