Selecting dates in SQL Server

K

Kevinp

I have a table with a date field and one of the
rows has a date value of '2009-03-31
16:39:16.000'.

I'm trying to use a SELECT statement like this:
SELECT * FROM MyTable WHERE fldDate >= '01/01/09'
AND fldDate <= '03/31/09'

The results will not include the above stated
record. Is there some way to change the SQL
statement that will include it?
 
A

Armin Zingler

Kevinp said:
I have a table with a date field and one of the
rows has a date value of '2009-03-31
16:39:16.000'.

I'm trying to use a SELECT statement like this:
SELECT * FROM MyTable WHERE fldDate >= '01/01/09'
AND fldDate <= '03/31/09'

The results will not include the above stated
record. Is there some way to change the SQL
statement that will include it?

'03/31/09' is equal to '03/31/09 00:00'

'2009-03-31 16:39:16.000' is not before and not equal to 03/31/09 00:00

If you want to include the 31th of March 2009, use

< '04/01/2009'

(which is also true if you use SQLParameters)


Armin
 
A

Armin Zingler

Kevinp said:
I have a table with a date field and one of the
rows has a date value of '2009-03-31
16:39:16.000'.

I'm trying to use a SELECT statement like this:
SELECT * FROM MyTable WHERE fldDate >= '01/01/09'
AND fldDate <= '03/31/09'

The results will not include the above stated
record. Is there some way to change the SQL
statement that will include it?

'03/31/09' is equal to '03/31/09 00:00'

'2009-03-31 16:39:16.000' is not before and not equal to 03/31/09 00:00

If you want to include the 31th of March 2009, use

< '04/01/2009'

(which is also true if you use SQLParameters)


Armin
 
K

Kevinp

'03/31/09' is equal to '03/31/09 00:00'

'2009-03-31 16:39:16.000' is not before and not equal to 03/31/09 00:00

If you want to include the 31th of March 2009, use

< '04/01/2009'

(which is also true if you use SQLParameters)


Armin

Yes, I realize that. Entering '04/01/09' is not
acceptable to my users who only want up to
'03/31/09'.
 
K

Kevinp

'03/31/09' is equal to '03/31/09 00:00'

'2009-03-31 16:39:16.000' is not before and not equal to 03/31/09 00:00

If you want to include the 31th of March 2009, use

< '04/01/2009'

(which is also true if you use SQLParameters)


Armin

Yes, I realize that. Entering '04/01/09' is not
acceptable to my users who only want up to
'03/31/09'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top