I need to get the date part only from SQL. SQL data type is date but when i tried to call it it returns this value 01-Mar-14 12:00:00 AM
. The only part I'm interested in is 01-Mar-14
I've a long search in stackoverflow and microsoft and google but in vain.
First search didn't work with me
also this one didn't work out
Here is my C# code to get these values.
private void SearchName_Click(object sender, EventArgs e)
{
db.con.Open();
SqlDataReader reader;
SqlCommand command = new SqlCommand("select * from Employee inner join DatePics on ID=Emp_ID where EmpName='" + SearNametxt.Text + "' ", db.con);
reader = command.ExecuteReader();
while (reader.Read())
{
NameSeartxt.Text = (reader["EmpName"].ToString());
PassSeartxt.Text = (reader["Passport"].ToString());
IDSeartxt.Text = (reader["IDIssue"].ToString());
expiryseartxt.Text = (reader["IDExpiry"].ToString());
}
db.con.Close();
}
but also return only the whole format. Tried to use this one, but fail.
select convert(varchar(10), '01-Mar-14 12:00:00', 120)
EDIT: latest code:
db.con.Open();
SqlDataReader reader;
SqlCommand command = new SqlCommand("select * from Employee inner join
DatePics on ID=Emp_ID where EmpName='" + SearNametxt.Text + "' ", db.con);
reader = command.ExecuteReader();
while (reader.Read())
{
DateTime Received;
DateTime.TryParse(reader["ReceivedDate"], CultureInfo.InvariantCulture,
DateTimeStyles.None, out Received);
recsearchtxt.Text = Received.ToString("d");