fetch only date from date datatype in sql server
Possible Duplicate:
How to return the date part only from a SQL Server datetime datatype
I need to fetch only date from sql server eventhough i have used date datatype i am getting time also. but in database n_strat_date
column has only date value not the time value.
My table:
My Output:
Regardless of how you store the dates in SQL, if you load this data in C# DateTime
values, they will always have a time part (which is 12:00:00 AM
, unless otherwise specified).
Your problem here has nothing to do with SQL; it's a formatting issue in your application.
Concretely, if you had the DateTime value in a variable called startDate
, instead of printing out to the form startDate
or startDate.ToString()
, use an explicit format, like this: startDate.ToString("M/d/yyyy")
.
Here's an online test to see how it works.
尝试它,它会从table_name中选择CONVERT(date,column_name)
链接地址: http://www.djcxy.com/p/94380.html