SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


want only date from date-time format


want only date from date-time format

Author
Message
adc22
adc22
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 33
Hi All, I'm new to sql. Of late I created a table (in sql 2000) using
create table EMP
(
EMPNO int,
ENAME CHAR(10),
JOB CHAR(10),
MGR INT null,
HIREDATE DATETIME,
SAL INT,
COMM INT NULL,
DEPTNO INT
)

the table looked like ...
7369 SMITH HEADCLERK 7566 1980-12-17 00:00:00.000 800 NULL 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00.000 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 00:00:00.000 2900 500 30

I want to get rid of that time part in the 'HireDate' column. I want only 1980-12-17 instead of 1980-12-17 00:00:00.000. please help me. Is declaring HIREDATE as a DATETIME incorrect? SQL 2000 perhaps does not accept DATE as data type, so I used DATETIME.
Also, if possible provide me a link from where I can study cast, convert & other similar utilities(sql 2000).
Thanking you in anticipation,
Sergey Vavinskiy
Sergey Vavinskiy
SSC-Addicted
SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)SSC-Addicted (487 reputation)

Group: General Forum Members
Points: 487 Visits: 392
It doesn't matter how it looks like in a table, but it is important how it looks like when you retrieve a data. So, you can convert it into different formats inside any of your SELECT statement like that:

SELECT CONVERT(CHAR(10), HIREDATE, 111) or
SELECT CONVERT(CHAR(10), HIREDATE, 105)

instead of just SELECT HIREDATE
adc22
adc22
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 33
THANKS Sergey .. it worked.... :-)
Britt Cluff
Britt Cluff
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1953 Visits: 253
SQL Server 2008 has a Date datatype which will solve your problem when you are able to upgrade.

http://brittcluff.blogspot.com/
Elliott Whitlow
Elliott Whitlow
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12928 Visits: 5314
Lynn has a nice page of common date routines at:
http://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search