note 58146 deleted from function.strtotime by nlopess
| From: | nlopess@php.net | Date: | Tue, 25 Oct 2005 17:53:38 +0000 |
| Subject: | note 58146 deleted from function.strtotime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97588@lists.php.net to get a copy of this message | ||
Note Submitter: $mr.obvious
Reason: bad code
----
A quick little note I found handy while working with a client that did not know how to prepare a
date field in a file that was being imported by a PHP script into MySQL... if the date field is kept
as VARCHAR in MySQL, the strtotime() function works quite well when comparing dates to get an active
member count (based on a subscription service where the date stored in MySQL is in the future).
I'm sure you can find other uses for it with simple modifications:
Example fgets from file upload: (FName,LName,Date)
"John","Doe","8/1/2007"
<?PHP
$query = "SELECT * FROM mbr_list";
$sql = mysql_query($query) or die(mysql_error());
$active=0;
while($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
$goodUntil = $row['Date'];
if (strtotime("now")<strtotime($goodUntil)){
$active++;
}
}
?>
Since strtotime interprets ASCII into a time format, a date doesn't have to be stored as a
'date' in MySQL (YYYY-MM-DD).