SQL: Select some data with date criteria, but only by Date part of date field 
Author Message
 SQL: Select some data with date criteria, but only by Date part of date field

Hi!

I want to select some data with date criteria, but only by Date part of date
field. This is an example:

DateField:

11.12.2002 04:08:12
12.12.2002 07:25:24
13.12.2002 05:19:01
13.12.2002 03:10:01

When I'm using:
Select * From XX Where DateField = '2002-12-13'

This just doesn't work (result is empty).

I'm using this:
"Select * From XX
Where (DateField between  CONVERT (DATETIME, '2002-12-13 00:00:00', 102) And
CONVERT(DATETIME, '2002-12-13   23:59:59', 102) )

Can anyone suggest something better?



Thu, 02 Jun 2005 04:16:56 GMT
 SQL: Select some data with date criteria, but only by Date part of date field

Nikolay,

First, pass the datetime value in a safe format, the format where you have separators isn't safe
unless you also execute the appropriate SET DATEFORMAT command. Below is an example of a safe
format:
'19980325 15:00:05

If you want to have a query where SQL Server and use an index on the datetime column, use below
strategy:

WHERE DateField >= '20021213' AND  Datefield < '20021214'

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...

Quote:

> Hi!

> I want to select some data with date criteria, but only by Date part of date
> field. This is an example:

> DateField:

> 11.12.2002 04:08:12
> 12.12.2002 07:25:24
> 13.12.2002 05:19:01
> 13.12.2002 03:10:01

> When I'm using:
> Select * From XX Where DateField = '2002-12-13'

> This just doesn't work (result is empty).

> I'm using this:
> "Select * From XX
> Where (DateField between  CONVERT (DATETIME, '2002-12-13 00:00:00', 102) And
> CONVERT(DATETIME, '2002-12-13   23:59:59', 102) )

> Can anyone suggest something better?



Wed, 01 Jun 2005 18:40:08 GMT
 SQL: Select some data with date criteria, but only by Date part of date field
Thanks, Tibor!

This works just fine :)



Quote:
> Nikolay,

> First, pass the datetime value in a safe format, the format where you have

separators isn't safe
Quote:
> unless you also execute the appropriate SET DATEFORMAT command. Below is

an example of a safe
Quote:
> format:
> '19980325 15:00:05

> If you want to have a query where SQL Server and use an index on the

datetime column, use below
Quote:
> strategy:

> WHERE DateField >= '20021213' AND  Datefield < '20021214'

> --
> Tibor Karaszi, SQL Server MVP
> Archive at:

http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...
Quote:




Quote:
> > Hi!

> > I want to select some data with date criteria, but only by Date part of
date
> > field. This is an example:

> > DateField:

> > 11.12.2002 04:08:12
> > 12.12.2002 07:25:24
> > 13.12.2002 05:19:01
> > 13.12.2002 03:10:01

> > When I'm using:
> > Select * From XX Where DateField = '2002-12-13'

> > This just doesn't work (result is empty).

> > I'm using this:
> > "Select * From XX
> > Where (DateField between  CONVERT (DATETIME, '2002-12-13 00:00:00', 102)
And
> > CONVERT(DATETIME, '2002-12-13   23:59:59', 102) )

> > Can anyone suggest something better?



Sat, 04 Jun 2005 00:20:40 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Replace part of Date field by another Date Field

2. Selecting dates in a query on a part of a date-syntax

3. ((Current Date - Start Date)/(End Date - Start Date))*Contract Amt

4. Selecting the earliest date from a DATE field

5. Selecting Date Fields that fall between two dates in Access

6. SELECT on part of a date field

7. date part of a date time

8. Retriveing only the date part ofthe date!!!

9. Query datetime-field by date when field contains date + time

10. Upsizing: Problems inserting date into SQL 7 date field

11. TimeStamp fields and Date selection criteria in SQL


 
Powered by phpBB® Forum Software