I have a sql query which extract a field of datatype smalldatetime. I read this field using datareader, convert it to string and store it in a string variable.
I get the string as 1/1/2012 12:00:00 AM ,here i want to use only date part of this string and i have nothing to do with the time.
How can i cut only the date from the string and get the output as 1/1/2012?
You may convert string to date type using Date.Parse() and use
ToShortDateString()As you said the type of field is smalldatetime then use
DataReader.GetDateTime(column_ordinal).ToString("d")method orDataReader.GetDateTime(column_ordinal).ToShortDateString()