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
 how to perform like search on datetime field

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-12-10 : 04:41:14
hi all,
i wanna to perform like search on datetime field

can anybody help me to solve this issue

thanks in advance

regards
Durgesh J

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-12-10 : 04:43:00
LIKE is for characters.
You can use BETWEEN to search a range of datetime.

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-10 : 04:43:52
can u explain ur requirement
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-12-10 : 04:45:30
You probably want DATEPART

I take it you want to query months / years / days?

You could so something like

WHERE
DATEPART(YEAR,<yourcolumn>) = 2008
AND DATEPART(DAY,<yourcolumn>) = 1

to find all 1st of the month entries in 2008 for example




Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-10 : 09:13:25
seems like intention for this is to get records for a day without considering timepart. in that case you need just this

WHERE datecolumn >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
AND datecolumn <DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
Go to Top of Page
   

- Advertisement -