Selecting dates in SQL Server

  • Thread starter Thread starter Kevinp
  • Start date Start date
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?
 
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
 
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
 
'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'.
 
'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'.
 
Back
Top