Thread: Wildcard in date field???

Wildcard in date field???

From
Web Manager
Date:
Hello,

I need to make a query that will select items that have a date matching
the current month for example.

For June this means that any day between 2000-06-01 and 2000-06-30 are
ok. To do that I need a wildcard like "%" to replace the actual day in
the date field.

Ex.:  select * from item where date = '2000-06-%%';

but that doesn't work... What is the right way?

Thanks!
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Marc Andre Paquin


Re: Wildcard in date field???

From
Dorin Grunberg
Date:

SELECT  * FROM my_table WHERE date_part('month', col_name::datetime) = '06' 
AND date_part('year', col_name::datetime) = '2000';

Looks for more detail in the manual for "date_part"

Dorin

At 03:52 PM 6/22/2000 -0400, Web Manager wrote:
>Hello,
>
>I need to make a query that will select items that have a date matching
>the current month for example.
>
>For June this means that any day between 2000-06-01 and 2000-06-30 are
>ok. To do that I need a wildcard like "%" to replace the actual day in
>the date field.
>
>Ex.:  select * from item where date = '2000-06-%%';
>
>but that doesn't work... What is the right way?
>
>Thanks!
>--
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Marc Andre Paquin



Re: Wildcard in date field???

From
Ed Loehr
Date:
Web Manager wrote:
> 
> I need to make a query that will select items that have a date matching
> the current month for example.
> 
> For June this means that any day between 2000-06-01 and 2000-06-30 are
> ok. To do that I need a wildcard like "%" to replace the actual day in
> the date field.
> 
> Ex.:  select * from item where date = '2000-06-%%';

Multiple ways to do it, but here's one:
select * from item where date_part('month',mydate) = 6   and date_part('year',mydate) = 2000;

Regards,
Ed Loehr