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
 General SQL Server Forums
 New to SQL Server Programming
 conversion from '%' to datetime

Author  Topic 

roop
Starting Member

9 Posts

Posted - 2007-09-11 : 03:05:00
hi,

i m facing a problem. I want to convert '%' into datetime format.
can any one provide me solution?

Thanx

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-11 : 03:09:24
What is % meant to represent?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-11 : 03:33:20
I'm guessing that the OP wants to do "wildcard" search on dates.

If you are looking for, say, Month = February you can do

SELECT *
FROM MyTable
WHERE DATEPART(Month, MyDateColumn) = 2

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-11 : 05:34:17
or


SELECT *
FROM MyTable
WHERE DATENAME(Month, MyDateColumn) = 'February'

provided language of the Server is English

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-09-11 : 05:45:38
or


SELECT *
FROM MyTable
WHERE DATENAME(Month, MyDateColumn) LIKE 'Feb%'

so not we have "%" in the query

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-11 : 05:50:32
quote:
Originally posted by Kristen

or


SELECT *
FROM MyTable
WHERE DATENAME(Month, MyDateColumn) LIKE 'Feb%'

so not we have "%" in the query

Kristen


Clever

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-09-11 : 05:58:44
Of course we could also do "When there is an R in the month":

SELECT *
FROM MyTable
WHERE DATENAME(Month, MyDateColumn) LIKE '%[Rr]%'

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-11 : 06:02:09
quote:
Originally posted by Kristen

Of course we could also do "When there is an R in the month":

SELECT *
FROM MyTable
WHERE DATENAME(Month, MyDateColumn) LIKE '%[Rr]%'

Kristen


But not specific to February

select * from
(
select '2005-02-01' as MyDateColumn union all select '2006-11-01'
) as T
WHERE DATENAME(Month, MyDateColumn) LIKE '%[Rr]%'


Madhivanan

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

- Advertisement -