SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sql Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mayiko
Starting Member

9 Posts

Posted - 05/21/2012 :  19:01:51  Show Profile  Reply with Quote
I have a field that has a datatype of Date. When I select this field in a stored procedure, sql is passing back a time with the date. When I run the select statement in SMS I just get the date. I do not want the time, and I am not even sure where it is coming from.

Here is the select statment:
Select s.SampleTakenDate, s.SampleTakenTime, s.SampleTakenBy, s.SampleReceivedDateTime, s.SampleReceivedBy, s.SampleStatus, s.SampleBottleLot, r.ReferenceNumber, ss.SampleSourceName, s.TestType
		from Sample s 
		left join  Reference r on r.ReferenceID = s.SampleReferenceID 
		left join SampleSource ss on ss.SampleSourceID = s.SampleSourceID
		where s.SampleBottleID = @bottleID


The field I am looking at is the very first one (SampleTakeDate).

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 05/21/2012 :  19:04:36  Show Profile  Reply with Quote
where are you seeing the timepart? date datatype wont show timepart under default conditions.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Mayiko
Starting Member

9 Posts

Posted - 05/21/2012 :  19:48:45  Show Profile  Reply with Quote
That is the weird part. If I run the query in SMS I do not see the time part, but I do see it when I look at it in Visual Studio, and on the textbox on the form it gets put into. Is it a c# issue, and not a sql issue? I do not know.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 05/21/2012 :  19:53:43  Show Profile  Reply with Quote
its a c# issue as you're assigning it to date datatype which also has time equivalent in c#

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Mayiko
Starting Member

9 Posts

Posted - 05/21/2012 :  20:23:57  Show Profile  Reply with Quote
Ok. This may need to be asked in a different forum, and if it does, please let me know. Here is how I am getting it from the SqlDataReader.

txtSampleDate.Text = reader["SampleTakenDate"].ToString();


How can I get just the date, and drop the time part?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 05/21/2012 :  20:37:33  Show Profile  Reply with Quote
try

txtSampleDate.Text = reader["SampleTakenDate"].ToString("dd/MM/yyyy");

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000