Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 datepart on varchar

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2005-12-08 : 13:14:18
I have a field that is define as varchar(10). I want to do a datepart on it and I get an error. How do I convert that field in sql to a date so that I can do a datepart against it.

Below is the sql statement

select * from test where datepart
(yyyy,appt_stop_date) < '1965'

X002548
Not Just a Number

15586 Posts

Posted - 2005-12-08 : 13:41:42
select * from test where datepart
(yyyy,CONVERT(datetime,appt_stop_date)) < 1965

DATEPART RETURNS int



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

csphard
Posting Yak Master

113 Posts

Posted - 2005-12-08 : 17:02:29
thanks that worked. I appreciate it
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-09 : 01:36:16
Hereafter use Proper DateTime Datatype to avoid this difficulty

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-09 : 02:15:42
I'm with you Maddy ...

"I have a [date] field that is define as varchar(10)"

I'd love to know why

Kristen
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2005-12-09 : 02:23:31
I have seen too many similar cases.

Looking at a table
"Who is the stupid programmer that keep date time in a varchar ? How can anybody design such a table.... this is rediculus"

Few minutes later after tracing and found out who is the "stupid programmer"
"Oh It's me .I must have done that when i am still new to SQL"

It happned too many times

-----------------
[KH]

Where Am I ?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-09 : 23:50:56
"Oh It's me .I must have done that when i am was still new to SQL"

Sorry, but you just can't use that old excuse anymore

Kristen
Go to Top of Page
   

- Advertisement -