Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Datetime


Message #1 by "Brian" <bpstings6@a...> on Sun, 2 Feb 2003 03:43:34
>Hi Bob,
Thanks for the tip. It worked and made my code look much neat compared to 
all that convert stuff I was doing. I guess was really overthinking this. 
I'll keep it simple in the future. 


> Hi Brian,
Suggest you don't convert to char. Stay with the datetime type for your
comparisions, let the database do the datetime maths.
Eg.
Select * from mytable where mydate is >= '1-JAN-2003' and mydate <=
'31-Jan-2003'
Regards
Bob


-----Original Message-----
From: Brian [mailto:bpstings6@a...] 
Sent: Sunday, 2 February 2003 3:44 a.m.
To: sql language
Subject: [sql_language] Datetime

I'm no good with converting dates so I can use them in comparisons. I 
select some columns from a table and included in the where clause is the

following:
select..from...where..
and work_date >= (select convert(char(2),month(GetDate())) + '/16/' + 
Convert(char(4),Year(GetDate())))
and work_date < (select convert(char(2),month(GetDate())) + '/31/' + 
Convert(char(4),Year(GetDate())))

So my prob is..if work_date column has values that look like
2002-01-31 00:00:00.000, 2002-01-19 00:00:00.000, 2002-01-25
00:00:00.000,
and my select convert statement above returns 2 /1/2003, then when I
look 
for work_date >= January 16 and <= January 31, no rows are returned. 

I don't know if that makes any sense, but that could be why I cna't
figure 
out. Any help appreciated. 

Thanks, Brian
---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to



  Return to Index