RE: [PHP-DB] String Convert
| From: | Rick Emery | Date: | Mon, 11 Feb 2002 17:40:31 +0000 |
| Subject: | RE: [PHP-DB] String Convert | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16810@lists.php.net to get a copy of this message | ||
You may wish to add a DATE field to your database and convert your
period_name input to that date using something like:
For each period_date, run this then write the $newdate to the added DATE
field:
<?php
list($mon,$yr) = explode("-",$period_date);
$newdate =
sprintf("20%s-%02d-01",$yr,strpos("000JanFebMarAprMayJunJulAugSepOctNovDec",
$mon)/3 );
?>
There's got to be an easier solution...
Then, you can run your SELECT statement
-----Original Message-----
From: Rankin, Randy [mailto:randy.rankin@invensys.com]
Sent: Monday, February 11, 2002 10:41 AM
To: php-db@lists.php.net
Subject: [PHP-DB] String Convert
I have a MySQL table called salesdata in which there is a field called
period_name of type varchar. The data is imported from a CSV file in the
following format:
Sep-00
Oct-00
Nov-00
...
Dec-01
I need to run the following query in order to select a range of periods:
Select distinct period_name
from salesdata
where salesperson = '$dbname'
and period_name between '$start_period' and '$end_period'
Does anyone know how to get around using a between statement on a string
field? I have experimented settype, but with no luck.
Any suggestions would be appreciated.
Thanks,
Randy Rankin