how do i get the date alone from datetime field from sql server.
eg
2015-01-29 10:17:37.000 from this i want only the date 2015-01-29
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sumit JoshiPosted Aug 13, 2015, 7:27 AM
Upendra Pratap ShahiPosted Aug 13, 2015, 7:24 AM
select CONVERT(VARCHAR(10),GETDATE(),110);
Rajeesh MenothPosted Aug 13, 2015, 7:18 AM
Ghanshyam BaravaliyaPosted Aug 13, 2015, 6:06 AM
Jignesh TrivediPosted Jan 29, 2015, 2:29 AM
you can casting this datetime field to date if you are using SQL server 2008 and above.
try...
select CAST('2015-01-29 10:17:37.000' as date)
select CAST(yourdatetimefiled as date) from table1
hope this will help you.
Michal HabalcikPosted Jan 29, 2015, 2:03 AM
SELECT CONVERT(date, getdate())
SELECT CAST(getdate() as date)
santhosh kumarPosted Jan 29, 2015, 12:42 AM
Suraj SahooPosted Jan 29, 2015, 12:35 AM
If you are not having the data type for the column as only "date" and the datatype is "datetime", then you will be saving the datetime object in the column.
And anticipating you have c# used. C# only has DateTime class. Even if you fetch date or datetime object c# understand datetime only. So you can have a viewmodel having the date property as string in C# and while retrieving and setting the value from SQL server, Use
Convert.ToDateTime(FETCHED DATE).ToShortDateString();
The ToShortDateString() returns only a date.
I hope this helps
Thanks