Making several variables into 1 variable

Making several variables into 1 variable

am 28.07.2009 15:32:09 von tmiller

I need to take this:

$pastDays =3D strtotime("-30 days");



$past_day =3D date("d", $pastDays);

$past_month =3D date("m", $pastDays);

$past_year =3Ddate("y", $pastDays);


And make it into one var to compare to a db field that is formatted like
00/00/00=20


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

Re: Making several variables into 1 variable

am 28.07.2009 15:35:23 von Ashley Sheridan

On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
> I need to take this:
>
> $pastDays = strtotime("-30 days");
>
>
>
> $past_day = date("d", $pastDays);
>
> $past_month = date("m", $pastDays);
>
> $past_year =date("y", $pastDays);
>
>
> And make it into one var to compare to a db field that is formatted like
> 00/00/00
>
>
Erm, why don't you do this:

$pastDays = strtotime("-30 days");
$date = date("d/m/y", $pastDays);

The date() function allows you to mix in all sorts of characters into
the output it formats, and you can escape characters that have special
meaning with a slash '\' character.

Thanks,
Ash
http://www.ashleysheridan.co.uk


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

Re: Making several variables into 1 variable

am 28.07.2009 15:36:07 von joao

Why not this:

$pastDate = date("d/m/y", strtotime("-30 days"));


""Miller, Terion"" escreveu na mensagem
news:C6946809.4183%kmiller13@springfi.gannett.com...
I need to take this:

$pastDays = strtotime("-30 days");



$past_day = date("d", $pastDays);

$past_month = date("m", $pastDays);

$past_year =date("y", $pastDays);


And make it into one var to compare to a db field that is formatted like
00/00/00



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

Re: Making several variables into 1 variable

am 28.07.2009 15:40:21 von rscrawford

On Tue, Jul 28, 2009 at 6:32 AM, Miller,
Terion wrote:
> I need to take this:
>
> =A0 $pastDays =3D strtotime("-30 days");
>
>
>
> $past_day =3D date("d", $pastDays);
>
> $past_month =3D date("m", $pastDays);
>
> $past_year =3Ddate("y", $pastDays);
>
>
> And make it into one var to compare to a db field that is formatted like
> 00/00/00

Try:

$past_date =3D date("m/d/y", $pastDays)

Or even:

$past_date =3D date ("m/d/y", time() - 2592000)

(where 2592000 is 30 * 86400, and 86400 is the number of seconds in one day=
..)




--=20
Richard S. Crawford (rscrawford@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

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

RE: Making several variables into 1 variable

am 28.07.2009 15:41:34 von Bob McConnell

From: Ashley Sheridan
> On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
>> I need to take this:
>>=20
>> $pastDays =3D strtotime("-30 days");
>>=20
>>=20
>>=20
>> $past_day =3D date("d", $pastDays);
>>=20
>> $past_month =3D date("m", $pastDays);
>>=20
>> $past_year =3Ddate("y", $pastDays);
>>=20
>>=20
>> And make it into one var to compare to a db field that is formatted
like
>> 00/00/00=20
>>=20
>>=20
> Erm, why don't you do this:
>=20
> $pastDays =3D strtotime("-30 days");
> $date =3D date("d/m/y", $pastDays);
>=20
> The date() function allows you to mix in all sorts of characters into
> the output it formats, and you can escape characters that have special
> meaning with a slash '\' character.

The problem with that is if that field is a string, and not formatted as
YY/MM/DD, then a simple compare won't work in January. You have to break
it down into the three components and compare each one in turn.

Bob McConnell

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

Re: Making several variables into 1 variable

am 28.07.2009 15:42:29 von tmiller

On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:

$pastDays =3D strtotime("-30 days");
$date =3D date("d/m/y", $pastDays);

Well I tried and got no results from my query and I know there results with=
date ranges in the last 30 days, I basically need to count backward from n=
ow() 30 days I thought strtotime() would work well..but the fields in the d=
b are varchar not date fields they are all formatted the same though 00/00/=
00:

$sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM rest=
aurants, inspections WHERE restaurants.name !=3D '' AND inspections.inDate =
<=3D $date GROUP BY restaurants.ID ORDER BY 'name' ";

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

Re: Making several variables into 1 variable

am 28.07.2009 15:44:48 von Ashley Sheridan

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>
>
> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
>
> Well I tried and got no results from my query and I know there results with date ranges in the last 30 days, I basically need to count backward from now() 30 days I thought strtotime() would work well..but the fields in the db are varchar not date fields they are all formatted the same though 00/00/00:
>
> $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
>

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

Thanks,
Ash
http://www.ashleysheridan.co.uk


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

Re: Making several variables into 1 variable

am 28.07.2009 15:45:50 von tmiller

On 7/28/09 8:41 AM, "Bob McConnell" wrote:

From: Ashley Sheridan
> On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
>> I need to take this:
>>
>> $pastDays =3D strtotime("-30 days");
>>
>>
>>
>> $past_day =3D date("d", $pastDays);
>>
>> $past_month =3D date("m", $pastDays);
>>
>> $past_year =3Ddate("y", $pastDays);
>>
>>
>> And make it into one var to compare to a db field that is formatted
like
>> 00/00/00
>>
>>
> Erm, why don't you do this:
>
> $pastDays =3D strtotime("-30 days");
> $date =3D date("d/m/y", $pastDays);
>
> The date() function allows you to mix in all sorts of characters into
> the output it formats, and you can escape characters that have special
> meaning with a slash '\' character.

The problem with that is if that field is a string, and not formatted as
YY/MM/DD, then a simple compare won't work in January. You have to break
it down into the three components and compare each one in turn.

Bob McConnell

Hi Bob, they are all formatted in the db as mm/dd/yy

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

RE: Making several variables into 1 variable

am 28.07.2009 15:46:07 von Ashley Sheridan

On Tue, 2009-07-28 at 09:41 -0400, Bob McConnell wrote:
> From: Ashley Sheridan
> > On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
> >> I need to take this:
> >>
> >> $pastDays = strtotime("-30 days");
> >>
> >>
> >>
> >> $past_day = date("d", $pastDays);
> >>
> >> $past_month = date("m", $pastDays);
> >>
> >> $past_year =date("y", $pastDays);
> >>
> >>
> >> And make it into one var to compare to a db field that is formatted
> like
> >> 00/00/00
> >>
> >>
> > Erm, why don't you do this:
> >
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> >
> > The date() function allows you to mix in all sorts of characters into
> > the output it formats, and you can escape characters that have special
> > meaning with a slash '\' character.
>
> The problem with that is if that field is a string, and not formatted as
> YY/MM/DD, then a simple compare won't work in January. You have to break
> it down into the three components and compare each one in turn.
>
> Bob McConnell
>
I assumed that the date field in MySQL was a date or datetime type. It
would be a little silly to store dates in the database any other way?

Thanks,
Ash
http://www.ashleysheridan.co.uk


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

Re: Making several variables into 1 variable

am 28.07.2009 15:46:54 von tmiller

On 7/28/09 8:44 AM, "Ashley Sheridan" wrote:

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>
>
> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>
> $pastDays =3D strtotime("-30 days");
> $date =3D date("d/m/y", $pastDays);
>
> Well I tried and got no results from my query and I know there results wi=
th date ranges in the last 30 days, I basically need to count backward from=
now() 30 days I thought strtotime() would work well..but the fields in the=
db are varchar not date fields they are all formatted the same though 00/0=
0/00:
>
> $sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM re=
staurants, inspections WHERE restaurants.name !=3D '' AND inspections.inDat=
e <=3D $date GROUP BY restaurants.ID ORDER BY 'name' ";
>

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

Thanks,
Ash
http://www.ashleysheridan.co.uk



Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol =
thanks guys!

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

Re: Making several variables into 1 variable

am 28.07.2009 15:52:49 von Ashley Sheridan

--=-9x89LTcimGkpjwt3hF4k
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:

>
>
> On 7/28/09 8:44 AM, "Ashley Sheridan" wrote:
>
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
> >
> >
> > On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
> >
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> >
> > Well I tried and got no results from my query and I know there results with date ranges in the last 30 days, I basically need to count backward from now() 30 days I thought strtotime() would work well..but the fields in the db are varchar not date fields they are all formatted the same though 00/00/00:
> >
> > $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
> >
>
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
> Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol thanks guys!
>

Euro/Brit date formatting? Nah, it's proper data formatting, not what
you crazy Yanks do! ;)


Thanks,
Ash
http://www.ashleysheridan.co.uk

--=-9x89LTcimGkpjwt3hF4k--

Re: Making several variables into 1 variable

am 28.07.2009 15:53:31 von Phpster

On Tue, Jul 28, 2009 at 9:46 AM, Miller,
Terion wrote:
>
>
>
> On 7/28/09 8:44 AM, "Ashley Sheridan" wrote:
>
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>>
>>
>> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>>
>> $pastDays =3D strtotime("-30 days");
>> $date =3D date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there results w=
ith date ranges in the last 30 days, I basically need to count backward fro=
m now() 30 days I thought strtotime() would work well..but the fields in th=
e db are varchar not date fields they are all formatted the same though 00/=
00/00:
>>
>> =A0 $sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM=
restaurants, inspections WHERE restaurants.name !=3D '' AND inspections.in=
Date <=3D $date GROUP BY restaurants.ID ORDER BY 'name' ";
>>
>
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
> Ah ha bet that's it didn't notice the euro/brit date formatting there. Lo=
l thanks guys!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Also check out Mysql sql date formating / date sub stuff, might make
things easier

--=20

Bastien

Cat, the other other white meat

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

Re: Making several variables into 1 variable

am 28.07.2009 15:55:16 von tmiller

On 7/28/09 8:52 AM, "Ashley Sheridan" wrote:

On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:



On 7/28/09 8:44 AM, "Ashley Sheridan" wrote:

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>
>
> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>
> $pastDays =3D strtotime("-30 days");
> $date =3D date("d/m/y", $pastDays);
>
> Well I tried and got no results from my query and I know there results wi=
th date ranges in the last 30 days, I basically need to count backward from=
now() 30 days I thought strtotime() would work well..but the fields in the=
db are varchar not date fields they are all formatted the same though 00/0=
0/00:
>
> $sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM re=
staurants, inspections WHERE restaurants.name !=3D '' AND inspections.inDat=
e <=3D $date GROUP BY restaurants.ID ORDER BY 'name' ";
>

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

Thanks,
Ash
http://www.ashleysheridan.co.uk



Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol =
thanks guys!

Euro/Brit date formatting? Nah, it's proper data formatting, not what you c=
razy Yanks do! ;)


Thanks,
Ash
http://www.ashleysheridan.co.uk

LOL I know we yanks bastardize everything...anyways it still didn't work...=
argh...so the boss thought he'd give me something harder...lovely, now I ha=
ve to figure out how to reverse publish things to quark....get ready guys I=
may be blowing the list up soon with questions (like I don't already)
Terion

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

Re: Making several variables into 1 variable

am 28.07.2009 15:59:19 von Ian

> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
> >
> >
> > On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
> >
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> >
> > Well I tried and got no results from my query and I know there results with date ranges in the last 30 days, I basically need to count backward from now() 30 days I thought strtotime() would work well..but the fields in the db are varchar not date fields they are all formatted the same though 00/00/00:
> >
> > $sql = " SELECT DISTINCT restaurants.ID, name, address, inDate
>> FROM restaurants, inspections
>> WHERE restaurants.name != '' AND inspections.inDate <= $date
>> GROUP BY restaurants.ID ORDER BY 'name' ";
> >
>
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.

Hi,

Instead of using php to work out the 30 days part you could just let the database do it:

$sql = " SELECT DISTINCT restaurants.ID, name, address, inDate
FROM restaurants, inspections
WHERE restaurants.name != '' AND

CAST(inspections.inDate AS DATE) <=
DATE_SUB(NOW(),INTERVAL 30 DAYS)

GROUP BY restaurants.ID ORDER BY 'name' ";

You will have to check that the CAST function is working properly on your varchar'ed date
fields before testing this query. It should point you in the right direction though.

Regards

Ian
--



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

Re: Making several variables into 1 variable

am 28.07.2009 16:01:18 von Floyd Resler

On Jul 28, 2009, at 9:55 AM, Miller, Terion wrote:

>
>
>
> On 7/28/09 8:52 AM, "Ashley Sheridan"
> wrote:
>
> On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:
>
>
>
> On 7/28/09 8:44 AM, "Ashley Sheridan"
> wrote:
>
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>>
>>
>> On 7/28/09 8:35 AM, "Ashley Sheridan"
>> wrote:
>>
>> $pastDays = strtotime("-30 days");
>> $date = date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there
>> results with date ranges in the last 30 days, I basically need to
>> count backward from now() 30 days I thought strtotime() would work
>> well..but the fields in the db are varchar not date fields they are
>> all formatted the same though 00/00/00:
>>
>> $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
>> restaurants, inspections WHERE restaurants.name != '' AND
>> inspections.inDate <= $date GROUP BY restaurants.ID ORDER BY 'name'
>> ";
>>
>
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the
> day
> like was in Richards example.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
> Ah ha bet that's it didn't notice the euro/brit date formatting
> there. Lol thanks guys!
>
> Euro/Brit date formatting? Nah, it's proper data formatting, not
> what you crazy Yanks do! ;)
>
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> LOL I know we yanks bastardize everything...anyways it still didn't
> work...argh...so the boss thought he'd give me something
> harder...lovely, now I have to figure out how to reverse publish
> things to quark....get ready guys I may be blowing the list up soon
> with questions (like I don't already)
> Terion
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You can also do this right within MySQL without needing to create a
variable. This should work:
$sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
restaurants, inspections WHERE restaurants.name != '' AND
datediff(curdate(),inspections.inDate)>=30 GROUP BY restaurants.ID
ORDER BY 'name' ";

Take care,
Floyd


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

Re: Making several variables into 1 variable

am 28.07.2009 16:24:58 von Carlos Medina

Miller, Terion schrieb:
> I need to take this:
>
> $pastDays = strtotime("-30 days");
>
>
>
> $past_day = date("d", $pastDays);
>
> $past_month = date("m", $pastDays);
>
> $past_year =date("y", $pastDays);
>
>
> And make it into one var to compare to a db field that is formatted like
> 00/00/00
>

$result = date("d/m/y", $pastDays);



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

RE: Making several variables into 1 variable

am 28.07.2009 16:34:37 von Bob McConnell

From: Miller, Terion
On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:

> $pastDays =3D strtotime("-30 days");
> $date =3D date("d/m/y", $pastDays);
>=20
> Well I tried and got no results from my query and I know there
> results with date ranges in the last 30 days, I basically need
> to count backward from now() 30 days I thought strtotime() would
> work well..but the fields in the db are varchar not date fields
> they are all formatted the same though 00/00/00:

If the dates are really stored as varchar, you are doing a lexical
comparison on a field that is meaningless in that context. You will need
to break the string down somewhere and do three separate comparisons.

Bob McConnell

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

Re: Making several variables into 1 variable

am 28.07.2009 16:40:05 von tmiller

<,snip>
>

You can also do this right within MySQL without needing to create a
variable. This should work:
$sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
restaurants, inspections WHERE restaurants.name !=3D '' AND
datediff(curdate(),inspections.inDate)>=3D30 GROUP BY restaurants.ID
ORDER BY 'name' ";

Take care,
Floyd



Ok I have to do the same thing again but with even more variables posted fr=
om a form
I have a form where a user can choose a date range currently the form retur=
ns 6 variables (bmonth, bday, byear, emonth, eday, eyear) now I have to tak=
e those and get them all formatted together (well the bmonth, bday, byear t=
ogether) in the mm/dd/yy format

Wait can't I.....
$month =3D $date(m, $bmonth) like that but then I still end up with 3

$month, $day, $year.... Does that work like that $date(m/d/y, $month, $day,=
$year)

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

Re: Making several variables into 1 variable

am 28.07.2009 16:40:27 von Phpster

On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell wrote:
> From: Miller, Terion
> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>
>> $pastDays = strtotime("-30 days");
>> $date = date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there
>> results with date ranges in the last 30 days, I basically need
>> to count backward from now() 30 days I thought strtotime() would
>> work well..but the fields in the db are varchar not date fields
>> they are all formatted the same though 00/00/00:
>
> If the dates are really stored as varchar, you are doing a lexical
> comparison on a field that is meaningless in that context. You will need
> to break the string down somewhere and do three separate comparisons.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Teri,

have you considered making the field a date/ datetime type? You could
add the column, then copy the data over with a sql statement casting
it to the correct date format you require and then drop the original
column

--

Bastien

Cat, the other other white meat

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

Re: Making several variables into 1 variable

am 28.07.2009 16:43:04 von tmiller

On 7/28/09 9:40 AM, "Bastien Koert" wrote:

On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell wrote:
> From: Miller, Terion
> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>
>> $pastDays =3D strtotime("-30 days");
>> $date =3D date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there
>> results with date ranges in the last 30 days, I basically need
>> to count backward from now() 30 days I thought strtotime() would
>> work well..but the fields in the db are varchar not date fields
>> they are all formatted the same though 00/00/00:
>
> If the dates are really stored as varchar, you are doing a lexical
> comparison on a field that is meaningless in that context. You will need
> to break the string down somewhere and do three separate comparisons.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Teri,

have you considered making the field a date/ datetime type? You could
add the column, then copy the data over with a sql statement casting
it to the correct date format you require and then drop the original
column

--

Bastien

Cat, the other other white meat

I don't think I can this data is being pulled from our county health site, =
so it comes in how they put it on their page (scraping here) and I'm grabb=
ing it using regex. (and this is totally public info so it's legit-my emplo=
yer tells me)



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

Re: Making several variables into 1 variable

am 28.07.2009 17:25:50 von Phpster

On Tue, Jul 28, 2009 at 10:40 AM, Miller,
Terion wrote:
>
>
>
> <,snip>
>>
>
> You can also do this right within MySQL without needing to create a
> variable. =A0This should work:
> $sql =3D "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
> restaurants, inspections WHERE restaurants.name !=3D '' AND
> datediff(curdate(),inspections.inDate)>=3D30 GROUP BY restaurants.ID
> ORDER BY 'name' ";
>
> Take care,
> Floyd
>
>
>
> Ok I have to do the same thing again but with even more variables posted =
from a form
> I have a form where a user can choose a date range currently the form ret=
urns 6 variables (bmonth, bday, byear, emonth, eday, eyear) now I have to t=
ake those and get them all formatted together (well the bmonth, bday, byear=
together) in the mm/dd/yy format
>
> Wait can't I.....
> $month =3D $date(m, $bmonth) like that but then I still end up with 3
>
> $month, $day, $year.... Does that work like that $date(m/d/y, $month, $da=
y, $year)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Use strtotime to convert a text string into a time value that php can
then use to figure out a date.

$date =3D date('m/d/y', strtotime("$month/$day/$year");

--=20

Bastien

Cat, the other other white meat

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

Re: Making several variables into 1 variable

am 28.07.2009 17:26:53 von Phpster

On Tue, Jul 28, 2009 at 10:43 AM, Miller,
Terion wrote:
>
>
>
> On 7/28/09 9:40 AM, "Bastien Koert" wrote:
>
> On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell wrote:
>> From: Miller, Terion
>> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>>
>>> $pastDays =3D strtotime("-30 days");
>>> $date =3D date("d/m/y", $pastDays);
>>>
>>> Well I tried and got no results from my query and I know there
>>> results with date ranges in the last 30 days, I basically need
>>> to count backward from now() 30 days I thought strtotime() would
>>> work well..but the fields in the db are varchar not date fields
>>> they are all formatted the same though 00/00/00:
>>
>> If the dates are really stored as varchar, you are doing a lexical
>> comparison on a field that is meaningless in that context. You will need
>> to break the string down somewhere and do three separate comparisons.
>>
>> Bob McConnell
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Teri,
>
> have you considered making the field a date/ datetime type? You could
> add the column, then copy the data over with a sql statement casting
> it to the correct date format you require and then drop the original
> column
>
> --
>
> Bastien
>
> Cat, the other other white meat
>
> I don't think I can this data is being pulled from our county health site=
, so it comes in how they put it on their page (scraping here) =A0and I'm g=
rabbing it using regex. (and this is totally public info so it's legit-my e=
mployer tells me)
>
>
>

Yep, if you are not in control of the data and are just screenscraping
a site, then you don't have too many choices.

--=20

Bastien

Cat, the other other white meat

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

Re: Making several variables into 1 variable

am 28.07.2009 18:03:07 von Shawn McKenzie

Bastien Koert wrote:
> On Tue, Jul 28, 2009 at 10:43 AM, Miller,
> Terion wrote:
>>
>>
>> On 7/28/09 9:40 AM, "Bastien Koert" wrote:
>>
>> On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell wrote:
>>> From: Miller, Terion
>>> On 7/28/09 8:35 AM, "Ashley Sheridan" wrote:
>>>
>>>> $pastDays = strtotime("-30 days");
>>>> $date = date("d/m/y", $pastDays);
>>>>
>>>> Well I tried and got no results from my query and I know there
>>>> results with date ranges in the last 30 days, I basically need
>>>> to count backward from now() 30 days I thought strtotime() would
>>>> work well..but the fields in the db are varchar not date fields
>>>> they are all formatted the same though 00/00/00:
>>> If the dates are really stored as varchar, you are doing a lexical
>>> comparison on a field that is meaningless in that context. You will need
>>> to break the string down somewhere and do three separate comparisons.
>>>
>>> Bob McConnell
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>> Teri,
>>
>> have you considered making the field a date/ datetime type? You could
>> add the column, then copy the data over with a sql statement casting
>> it to the correct date format you require and then drop the original
>> column
>>
>> --
>>
>> Bastien
>>
>> Cat, the other other white meat
>>
>> I don't think I can this data is being pulled from our county health site, so it comes in how they put it on their page (scraping here) and I'm grabbing it using regex. (and this is totally public info so it's legit-my employer tells me)
>>
>>
>>
>
> Yep, if you are not in control of the data and are just screenscraping
> a site, then you don't have too many choices.
>

Why? If you're scraping it then you can cast it into whatever form you
want before you store it in the db. Scrape it, strtotime(), store it?

--
Thanks!
-Shawn
http://www.spidean.com

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