December 10, 2008 at 5:19 pm
How can i get date only from datatime filed.
CAST(FLOOR(CAST(GetDate() AS FLOAT)) AS DATETIME) i tried this but still getting 2008-12-10 00:00:00.000
I only want 12/10/2008
please guide!!
I tried cast and convert but still getting same answer i might be doing something wrong?
December 10, 2008 at 5:34 pm
As long as it's datetime, you'll still get the time field. Try using the CONVERT with 101 and CAST to VARCHAR. That should do what you need.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
December 10, 2008 at 5:47 pm
so will it be
select CONVERT ( smalldatetime , start_date , 101 ) from table
December 10, 2008 at 6:21 pm
Yeah, but why do you want to format the code is SQL? Unless you're formatting to write to a file, then you should let the formatting be done in the GUI.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 10, 2008 at 7:32 pm
pat (12/10/2008)
so will it beselect CONVERT ( smalldatetime , start_date , 101 ) from table
No, you need to convert to a string datatype (char, nchar, varchar, nvarchar). Since the format is fixed, using char would be the best choice:
SELECT CONVERT(char(10), start_date, 101) FROM table;
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
December 10, 2008 at 7:40 pm
Or if you want to make things easier, at least for me, use DAY(), MONTH(), YEAR() and concatenate those (after casting to char)
December 11, 2008 at 5:48 am
Yeah, what Jeffrey wrote is correct for the cast & conversion. However, I do agree with Jeff. Normally I wouldn't recommend doing this sort of formatting in SQL Server.
BTW, 2008 introduces data and time data types in addition to the good old datetime.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply