I tried to convert sql datetime to string (hh:mm:ss), or filetime, but i wasn't successful.
Will somebody help me with my problem? I don't know how I can solve my problem really.
Thank'sWhat have you tried? Have you tried T-SQL'sCONVERT function?
|||Yes, I have, but I haven't successful.|||Well rather than us guessing, tell us what you've tried and we can helpyou troubleshoot your code. Let us know the data you have, thedata you want, and the code you're using to try to get there.
|||
Ok,
code is below:
...........
//split_time is sql datetime
myCommand.CommandText = "Select CAST(split_time AS timestamp) AS result from "some_table"+
" where number = '100' and control = '1'";
myCommand.Connection = connection;
//connection is ref SqlConnection connection (= connection string isn't null)
connection.Open();
SqlDataReader dr = myCommand.ExecuteReader();
while(dr3.Read())
{
string time = dr["result"].ToString();//I WANT TO FORMAT result AS STRING IN FORMAT hh:mm:ss
}
dr.Close();
connection.Close;
Thank's for help
The largest part of your problem is that you are CASTing AS a timestamp column. With SQL Server,timestampis a misleading, misnamed data type as it is actually a binary datatype related to row versioning. As a developer you should neverneed to use the timestamp data type. What you really need is thedatetime data type. What is the data type of your split_time column?
Check outDateTimeFormatInfo for help on the parameters to choose for the ToString method.
|||Thank's a lot for your help with datetime data type. It works good !
No comments:
Post a Comment