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
 SQL Server Development (2000)
 Casting a Varchar to a Day the to Varchar

Author  Topic 

AlexP
Starting Member

34 Posts

Posted - 2005-08-25 : 10:39:31
I need to get the day of the month like this 05 from this value.

01\05\1978

I get the error: Syntax error converting datetime from character string.

I am using this code:
CAST(day('01\05\1978') as varchar)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-25 : 10:43:51
If your table has datetime column then you can simply use
Select day(DatetimeColumn) from yourTable
Otherwise you have to convert it to datetime

Select day(CAST('01/05/1978' as datetime))




Madhivanan

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

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-08-25 : 12:13:03
You cannot use backslashes in a date format. Need to convert them to forward slashes:

SELECT CAST(day(REPLACE('01\05\1978', '\', '/')) as varchar)
Go to Top of Page
   

- Advertisement -