Date question

Date question

am 13.03.2006 04:44:13 von Gerry Danen

------=_Part_5431_18166383.1142221453782
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

While I am rebuilding my crashed laptop (the machine that had all my
intelligence), I started thinking about a select statement I need.

I have log info in a table and want to extract it on a monthly basis. The
date field is in yyyy-mm-dd format. What's a good way to select those dates
that match 2006-02, for example.

I apologize if the solution should be staring me in the face, but all my
favorites and help files are toast, until I can restore some of them.

TIA.

Gerry

------=_Part_5431_18166383.1142221453782--

Re: Date question

am 13.03.2006 05:11:38 von LJ Regalado

------=_Part_8127_21508970.1142223098873
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

For example, you have table `logs` with `datelog` field and you want to
select dates
that match 2006-02. You can try this select statement:

SELECT * FROM `logs` WHERE MONTH(datelog)=3D'02' and YEAR(datelog)=3D'2006'

Hope that helps.

LJ Regalado

------=_Part_8127_21508970.1142223098873--

Re: Date question

am 13.03.2006 05:12:24 von Chris

Gerry Danen wrote:
> While I am rebuilding my crashed laptop (the machine that had all my
> intelligence), I started thinking about a select statement I need.
>
> I have log info in a table and want to extract it on a monthly basis. The
> date field is in yyyy-mm-dd format. What's a good way to select those dates
> that match 2006-02, for example.
>
> I apologize if the solution should be staring me in the face, but all my
> favorites and help files are toast, until I can restore some of them.

Which database are you using?

Mysql has this:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functio ns.html

Postgresql has:
http://www.postgresql.org/docs/8.1/static/functions-datetime .html

I'm sure others have the same sort of functionality.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Date question

am 13.03.2006 16:23:02 von Bastien Koert

select * from table where date_format(date_field, '%Y-%m') = '2006-02'


bastien


>From: "Gerry Danen"
>To: php-db@lists.php.net
>CC: php_and_mysql@yahoogroups.com
>Subject: [PHP-DB] Date question
>Date: Sun, 12 Mar 2006 20:44:13 -0700
>
>While I am rebuilding my crashed laptop (the machine that had all my
>intelligence), I started thinking about a select statement I need.
>
>I have log info in a table and want to extract it on a monthly basis. The
>date field is in yyyy-mm-dd format. What's a good way to select those dates
>that match 2006-02, for example.
>
>I apologize if the solution should be staring me in the face, but all my
>favorites and help files are toast, until I can restore some of them.
>
>TIA.
>
>Gerry

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Date question

am 14.03.2006 07:03:21 von Gerry Danen

------=_Part_2507_3782317.1142316201151
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Thanks for all the help, guys. I'm back up, but a lot of my cool tricks are
gone. Gotta get a better backup plan...

Gerry

On 3/12/06, Gerry Danen wrote:
>
> While I am rebuilding my crashed laptop (the machine that had all my
> intelligence), I started thinking about a select statement I need.
>
> I have log info in a table and want to extract it on a monthly basis. The
> date field is in yyyy-mm-dd format. What's a good way to select those dat=
es
> that match 2006-02, for example.
>
> I apologize if the solution should be staring me in the face, but all my
> favorites and help files are toast, until I can restore some of them.
>
> TIA.
>
> Gerry
>
>


--
Gerry
http://portal.danen.org/

------=_Part_2507_3782317.1142316201151--

Re: Date question

am 17.03.2006 19:32:39 von Gerry Danen

------=_Part_6414_2388439.1142620359865
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

This works perfect, Bastien!

Many thanks.

Gerry

On 3/13/06, Bastien Koert wrote:
>
> select * from table where date_format(date_field, '%Y-%m') =3D '2006-02'
>
>
> bastien
>
>
> >From: "Gerry Danen"
> >To: php-db@lists.php.net
> >CC: php_and_mysql@yahoogroups.com
> >Subject: [PHP-DB] Date question
> >Date: Sun, 12 Mar 2006 20:44:13 -0700
> >
> >While I am rebuilding my crashed laptop (the machine that had all my
> >intelligence), I started thinking about a select statement I need.
> >
> >I have log info in a table and want to extract it on a monthly basis. Th=
e
> >date field is in yyyy-mm-dd format. What's a good way to select those
> dates
> >that match 2006-02, for example.
> >
> >I apologize if the solution should be staring me in the face, but all my
> >favorites and help files are toast, until I can restore some of them.
>

------=_Part_6414_2388439.1142620359865--