Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

I am using sql 2005. here is my table information:
KICKOFF MTG     4/1/1995 12:00:00 AM    4/1/1995 12:00:00 AM
TECH SURVEY     4/2/1995 12:00:00 AM    5/1/1995 12:00:00 AM
USER MTGS       5/15/1995 12:00:00 AM   5/30/1995 12:00:00 AM
DESIGN WIDGET   6/1/1995 12:00:00 AM    6/30/1995 12:00:00 AM
CODE WIDGET     7/1/1995 12:00:00 AM    9/2/1995 12:00:00 AM

when i run a query stated below the output shows....
SQL
SELECT TASK, STARTDATE, ENDDATE ORIGINAL_END, DATEADD (year,2,ENDDATE) FROM PROJECT;

OUTPUT:
KICKOFF MTG     1995-04-01 00:00:00.000 1995-04-01 00:00:00.000 1997-04-01 00:00:00.000
TECH SURVEY     1995-04-02 00:00:00.000 1995-05-01 00:00:00.000 1997-05-01 00:00:00.000
USER MTGS       1995-05-15 00:00:00.000 1995-05-30 00:00:00.000 1997-05-30 00:00:00.000
DESIGN WIDGET   1995-06-01 00:00:00.000 1995-06-30 00:00:00.000 1997-06-30 00:00:00.000
CODE WIDGET     1995-07-01 00:00:00.000 1995-09-02 00:00:00.000 1997-09-02 00:00:00.000

Now i wanna know what will be the query should i run to show only date and for only time?

Thanks

RHRaj
Posted
Updated 7-Apr-14 22:21pm
v2

Check this link:Date Formats Sql Server[^]
If you want only Date or time, u can use convert[^] or Cast
SQL
Select CONVERT(VARCHAR(5),GetDate(),114) [Time HH:MM],Cast(Getdate() as Time) [Time]
Select CONVERT(VARCHAR(10), GETDATE(), 102) [Date YYYY.MM.DD],Cast(GetDate() as Date) [Date YYYY-MM-DD]

But Convert is Recommended...
 
Share this answer
 
For SQL Server 2008 and above, you can try a CAST to DATE like below

SQL
SELECT CAST(GetDate() AS DATE) 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900