Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Issue 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
Is there a way to take "23 Nov 2006" and use it to query a datetime field (i.e. 11/23/2006 7:45:12 PM)

[conehead]
 
Code:
Select *
From   Table
Where  DateAdd(Day, DateDiff(Day, 0, DateField), 0) = '23 Nov 2006'

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
you should be able to use WHERE dateField > '10-Nov-2006' and it will return any rows where datefield is after 10-Nov-2006 00:00:00

 
From a performance perspective, this should run faster and also return the same data.

Code:
Declare @Temp DateTime
Set @Temp = '23 Nov 2006'

Select *
From   Table
Where  DateField >= @Temp
       And DateField < @Temp + 1

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Code:
DECLARE @Test varchar(50)
DECLARE @Test1 varchar(50)
DECLARE @Test2 varchar(3)
SET @Test = 'JanFebMarAprMayJunJulAugSepOctNovDec'
SET @Test1 = '23 Nov 2006'
SET @Test2 = SUBSTRING(@Test1,4,3)
print convert(datetime, RIGHT(@Test1,4)+RIGHT('00'+CAST(CharIndex(@Test2,@Test)/3+1 as varchar(2)),2)+LEFT(@Test1,2))

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
George,
this raise error on my computer:
Code:
DECLARE @Test datetime
SET @Test = '23 Nov 2006'

Msg 241, Level 16, State 1, Line 2
Syntax error converting datetime from character string.


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Boris. It's a regional setting thing...

Code:
[!]Set language 'us_english'[/!]
DECLARE @Test datetime
SET @Test = '23 Nov 2006'


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
If you run...

[!]sp_helplanguage[/!]

You will see the acceptable month abbreviations for various languages.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
:)
I know, just maybe my sense of humor today is rough :), or it is absent at all :).
I just wanted to point that this conversion is language dependent. Sorry.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top