note 58146 added to function.strtotime
| From: | $mr dot obvious at osu1 dot php dot net | Date: | Tue, 25 Oct 2005 17:28:49 +0000 |
| Subject: | note 58146 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97586@lists.php.net to get a copy of this message | ||
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).
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58146
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58146&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58146&report=yes
Search -- http://master.php.net/manage/user-notes.php