Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sql Date

Author  Topic 

Mayiko
Starting Member

9 Posts

Posted - 2012-05-21 : 19:01:51
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

52326 Posts

Posted - 2012-05-21 : 19:04:36
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 - 2012-05-21 : 19:48:45
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

52326 Posts

Posted - 2012-05-21 : 19:53:43
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 - 2012-05-21 : 20:23:57
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

52326 Posts

Posted - 2012-05-21 : 20:37:33
try

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

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

Go to Top of Page
   

- Advertisement -