note 59946 added to function.date
| From: | deadeyepi at osu1 dot php dot net | Date: | Tue, 20 Dec 2005 22:35:41 +0000 |
| Subject: | note 59946 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100490@lists.php.net to get a copy of this message | ||
Hey all, I used the script from Jay J in our FBLA chapter's website, and i needed to adapt it
to print out the beginning dates and end dates of our conferences. Also, since i have more than one
result, i also had to find a way for the function to be redefined. Below are the results, the files
are separated by **NEW FILE (filename)**
Be sure not to put the **'s and anything between them in your coding, it will cause the code to
crash.
**NEW FILE (mydate.php)**
<?
function mydate($format, $publictime)
{
$sec = substr($publictime, 12, 2);
$min = substr($publictime, 10, 2);
$hour = substr($publictime, 8, 2);
$day = substr($publictime, 6, 2);
$month = substr($publictime, 4, 2);
$year = substr($publictime, 0, 4);
return date($format, mktime($hour, $min, $sec, $month, $day, $year));
unset($year);
unset($day);
unset($month);
unset($sec);
unset($min);
unset($hour);
}
//OK before moving on, save this file as mydate.php and EXIT
?>
**BEFORE MOVING ON, open the file that you want the dates to display in**
**OPEN FILE (The file that the dates will be displayed in.)**
<?
require_once("mydate.php");
//The LOOPHOLE!!!
$datetime = "".MySQL_RESULT($Result,$i,"begdate")."";
//Gets the result from the Query
$justdate = "".MySQL_RESULT($Result,$i,"enddate")."";
//Same as above
echo mydate("Y-m-d", $datetime);
// Produces 2005-09-05 assuming the SQL result is 20050905
echo mydate("Y-m-d", $justdate);
// Produces 2005-09-15 assuming the SQL result is 20050915
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59946
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59946&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59946&report=yes
Search -- http://master.php.net/manage/user-notes.php