pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Wildcard in date field???
4+ messages / 4 participants
[nested] [flat]

* Wildcard in date field???
@ 2000-06-22 19:52 Web Manager <web@inter-resa.com>
  2000-06-22 20:37 ` Re: Wildcard in date field??? Ed Loehr <eloehr@austin.rr.com>
  2000-06-22 21:27 ` Re: Wildcard in date field??? Dorin Grunberg <dorin@visgen.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Web Manager @ 2000-06-22 19:52 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Wildcard in date field???
  2000-06-22 19:52 Wildcard in date field??? Web Manager <web@inter-resa.com>
@ 2000-06-22 20:37 ` Ed Loehr <eloehr@austin.rr.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Ed Loehr @ 2000-06-22 20:37 UTC (permalink / raw)
  To: Web Manager <web@inter-resa.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Wildcard in date field???
  2000-06-22 19:52 Wildcard in date field??? Web Manager <web@inter-resa.com>
@ 2000-06-22 21:27 ` Dorin Grunberg <dorin@visgen.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Dorin Grunberg @ 2000-06-22 21:27 UTC (permalink / raw)
  To: Web Manager <web@inter-resa.com>; pgsql-sql



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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Wildcard in date field
@ 2000-06-24 05:14 K Parker <kparker@eudoramail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: K Parker @ 2000-06-24 05:14 UTC (permalink / raw)
  To: pgsql-sql@hub.org

The suggest solution works:

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

But you can also just do a comparison:

  where col_name >= '2000-06-01' AND col_name <= '2000-06-30'

Using the correct date format for your environment, of course.



Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2000-06-24 05:14 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-22 19:52 Wildcard in date field??? Web Manager <web@inter-resa.com>
2000-06-22 20:37 ` Ed Loehr <eloehr@austin.rr.com>
2000-06-22 21:27 ` Dorin Grunberg <dorin@visgen.com>
2000-06-24 05:14 Re: Wildcard in date field K Parker <kparker@eudoramail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox