|
|
|
|
|
|
| |
After a long time of hardworking and fixing the problems in the old version, I am proud to release v1.01.
This is a simple dat/time manger class that can be easily plugged in o your system. Here goes
class.datetime_functions.php
Includes a number of functions that are date/time related.
leapinglangoor http://leapinglangoor.l2p.net
ver - 1.0.1
| <?php
class datetime_functions
{
// constructor
function datetime_functions()
{
$this->_class_name = "Date/Time Functions Class";
$this->_class_version = "1.0.0";
$this->_class_author = "leapinglangoor";
}
// returns a nicely formatted date string for a SQL date format
function sqldate_to_string($t="",$short=0)
{
if ($t=="") return "";
if (!$short) $months = array(
"January","Februrary","March","April","May","June","July",
"August","September","October","November","December"
);
else $months = array(
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
);
if (ereg("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})",$t,$args))
return sprintf("%s %d, %s",$months[$args[2]-1],$args[3],$args[1]);
else if (ereg("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})",$t,$args))
return sprintf("%s %d, %s",$months[$args[2]-1],$args[3],$args[1]);
else return $t;
}
// a function to convert number of seconds (eg; 96172) to a readable format
// such as: 1 day, 2 hours, 42 mins, and 52 secs
// takes unix timestamp as input
// Based on the word_time function from PG+ (http://pgplus.ewtoo.org)
function time_to_string($t=0)
{
if (!$t) return "no time at all";
if ($t < 0) {
$neg = 1;
$t = 0 - $t;
}
$days = $t / 86400;
$days = floor($days);
$hrs = ($t / 3600) % 24;
$mins = ($t / 60) % 60;
$secs = $t % 60;
$timestring = "";
if ($neg) $timestring .= "negative ";
if ($days) {
$timestring .= "$days day" . ($days==1?"":"s");
if ($hrs || $mins || $secs) $timestring .= ", ";
}
if ($hrs) {
$timestring .= "$hrs hour" . ($hrs==1?"":"s");
if ($mins && $secs) $timestring .= ", ";
if (($mins && !$secs) || (!$mins && $secs)) $timestring .= " and ";
}
if ($mins) {
$timestring .= "$mins min" . ($mins==1?"":"s");
if ($mins && $secs) $timestring .= ", ";
if ($secs) $timestring .= " and ";
}
if ($secs) $timestring .= "$secs sec" . ($secs==1?"":"s");
return $timestring;
}
// a function to return a string of when the file was last updated in a slightly
// fuzzy way. Takes a unix timestamp as input.
function FuzzyTime($time)
{
// sod = start of day :)
$now = time();
$sod = mktime(0,0,0,date("m",$time),date("d",$time),date("Y",$time));
$sod_now = mktime(0,0,0,date("m",$now),date("d",$now),date("Y",$now));
if ($sod_now == $sod) return "today at " . date("g:ia",$time); // check 'today'
if (($sod_now-$sod) <= 86400) return "yesterday at " . date("g:ia",$time); // check 'yesterday'
if (($sod_now-$sod) <= (ONE_DAY*5)) return date("l \a\\t g:ia",$time); // give a day name if within the last 5 days
if (date("Y",$now) == date("Y",$time)) return date("M j \a\\t g:ia",$time); // miss off the year if it's this year
return date("M j, Y \a\\t g:ia",$time); // return the date as normal
}
} // end class
?> | |
And just in case you want an example script for the above,
Original example script for class.datetime_functions.php
Lets begin
Brief description and purpose of this file
To give you a clear cut view on how the class can become useful.
There aew three functions in the class:
1. sqldate_to_string();
2. time_to_string();
3. Fuzzy Time();
The descriptions for the these functions() can be found in the class
I'm just gonna give you an idea on how to use it.
O.K lets begin
Usage Example:
| <?php
include('class.datetime_functions.php');
$functions = new datetime_functions;
$formated_t = $functions -> sqldate_to_string("2004-06-12 17:38:14");
echo('This is to convert the date from sql to a formatted string.<br>2004-06-12 17:38:14 <b> - becomes - </b> ' . $functions -> sqldate_to_string("2004-06-12 17:38:14"));
echo('<br><br>');
echo('This is to convert seconds to a formatted date string.<br>96172 <b> - becomes - </b> ' . $functions -> time_to_string(96172));
echo('<br><br>');
echo('This is to convert a Timestanp to a formatted date string.<br>20040612173814 <b> - becomes - </b> ' . $functions -> FuzzyTime(20040612173814));
echo('<br>');
?> | |
|
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | A time measuring and performance benchmarking class Categories : PHP, PHP Classes, Testing, Debugging, Date Time | | | Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | |
| | | | Jose Santos wrote :1127
Date & Time it`s very useful !!
The mktime() function simplify so mutch your script !!
Example: $timestamp = mktime(0,0,0,6,14,1971);
// that returns 06-14-1971
See in PHP manual (www.php.net) in section Date & Time.
And if the database is oracle, this had a two date functions to_char() and to_date
Example1 (insert): $sql = "insert into birtdays values(`José Santos`,to_date(`06-04-1971`,`MM-DD-YYYY`)"
Example (select every people that birth in thhe year 1971)
$sql = "select to_char(birth,`MM-DD-YYYY`) where to_char(birth,`YYYY`) = `1971`";
| |
|
|
|