The Identification Number and Password fields need to be filled in. Moreover, you cannot send messages devoid of contents Adding further data is not allowed because this topic has been closed Print You provided no password: you have to write it in the textfield beside the command delete for the topic you want to delete Are you sure you want to delete this comment? You did not cast a vote. You need to cast a vote by selecting a radio button. Impossible to proceed Provide the project number Insufficient form parameters: you forgot to fill in some field/s
 
member picmember pic
 
Snippets of A
 
info Below you can find the text of the snippet you want to read, and the list of the other snippets by this author if available.
What are snippets?
Share on MySpace

PHP Date: Disaggregated Date Difference As Interlapsed Days Hours Minutes Second

Snippet: Identification Number »   Snippet: Inclusion syntax »
Visitors: 8,867 Tagged by its author as: Programming Php Characters (in origin): 4,279 (pages: ~ 2)
Author: Em@il Permalink Cast your vote for this topic Printable version
OBJECTIVE: given two dates either in Sql format or as Unix timestamps, make their difference and return the time difference both as an aggregated representation (difference expressed only in seconds, only in minutes, only in hours, only in days) and as a disaggregated representation (difference expressed as how many days hours minutes and seconds have elapsed overall).
function disaggregatedTime($small='', $big=''){
/*validate:*/for($v=0, $a=func_get_args(); $v<sizeof($a); $v++){if(!trim($a[$v])){$a[$v]=time();}; if(strpos(trim($a[$v]), ' ')!==false){$a[$v]=strtotime($a[$v]);}; }
/*init:*/$small=$a[0]; $big=$a[1]; $times=array(86400/*d*/,3600/*h*/, 60/*m*/, 1/*s*/); $times2=array(24,60,60,1); $L=sizeof($times); $output=array();
/*RUN:*/$diff=$big - $small;
for($i=0; $i<$L; $i++){
$computation=$diff/$times[$i]; $output[$i]=floor($computation);
$float=explode('.', $computation); $float=(isset($float[1]))?'0.'.$float[1]:0;
$toreal=round( $float * $times2[$i] , 5 ); 
	switch($i){
	case 0: $output['realdays']=$output[$i];
		$output['realhours']=(abs($toreal)>=1)?intval($toreal):0; break;
	case 1: $output['realminutes']=(abs($toreal)>=1)?intval($toreal):0; break;
	case 2: $output['realseconds']=(abs($toreal)>=1)?intval($toreal):0; break;
	}
}return $output;/*keep this comment to reuse freely
http://www.fullposter.com/?1 */}
Remove colors  
INPUTS: both are Strings. They must be dates either represented as Unix timestamps, or in the following highly specific format (an UTC notation with one whitespace as designator):  
yyyy-mm-dd hh:mm:ss  
 
The first argument ought to be the earlier ("smaller") date, although no validation for this requirement is performed.  
 
If no inputs are passed, they will both default to the current timestamp.  
 
RETURNS: an associative array whose key/values pairs (keys are numbers and strings both, values are always numbers) are as follows:  
0 = aggregated days  
'realdays' = disaggregated days  
1 = aggregated hours  
'realhours' = disaggregated hours  
2 = aggregated minutes  
'realminutes' = disaggregated minutes  
3 = aggregated seconds  
'realseconds' = disaggregated seconds
 
 
CAVEATS: given the presence of leap years and of different amounts of days in a month, the function does not add representations in months and years: however, were it to be needed, it ought to be worked out considering the starting offset date and the returned aggregated days. Or, for such purpose you may use instead: Php Date: Full Disaggregated Date Difference Accounting Timezones And Daylight.  
 
The functions performs a rounding to avoid the notorious accuracy problem: this rounding allows 5 floating digits, and were you to need to change that amount the concerned line is:
$toreal=round( $float * $times2[$i] , 5 ); 
Remove colors  
If you pass as first argument a date that is not the earlier (therefore inverting the way the function is designed to operate), the returned value of the day (if the difference spans throughout at least one day) will be negative but the others will still be positive so you cannot rely on them to determine whether this was a case of negative difference.  
 
Remember that the returned values may amount also to zero, in case you want to skip them from print.  
 
Example of use:
$foo=disaggregatedTime('2005-03-23 22:05:30', '2005-03-24 20:04:29');

echo "Between <strong>2005-03-23 22:05:30</strong> and <strong>2005-03-24 20:04:29</strong> the difference is: {$foo['realdays']} days, {$foo['realhours']} hours, {$foo['realminutes']} minutes, {$foo['realseconds']} seconds";
Remove colorsSuch example would print:  
Between 2005-03-23 22:05:30 and 2005-03-24 20:04:29 the difference is: 0 days, 21 hours, 58 minutes, 59 seconds
Printable version To exclude hyperlinks from the print, check the checkbox »
Rss

Cast your vote for this topic

To perform this operation it is not necessary to be Full Poster members.
«Negative Positive»
Click here to save your vote (Current average: 0.00, Voters: 0)
Are you the author of this topic and do you want to append quickly more text? click here
Other topics
This subscriber has a blog too: Read the blog: 57 Shoutbox: 103 reviews: 153
Visitors: 8,867
Overall visits to all the topics: 4,969,537
Daily average (Calculated from the website subscription day): 2,062.05
Optional sorting commands:
Normal order: click here
Order by amount of visits: click here
Order by category: Programming Php
Current order: by category: Books
Other categories available for this author (Limited data report: 100):
Advice: Martial Arts and Self Defense(4), Books(236), Critical Reviews and Essays(4), Dictionaries(1), Emergency Care(4), Epistles Letters and Advice(5), Fantasy Epics and Fables(1), History and Documents(5), Humor and Jokes(2), Methematics(2), Music and Lyrics(6), News Digests and Press Reviews(1), Novels Poetry and Stories(3), Philosophy Reviews(7), Poetry(1), Programming(4), Programming Ajax(2), Programming Javascript(82), Programming Php(52), Psychology(1), Quotes(1), Religion Esoterica and Spirituality(12), Scientifical Reviews(4), Self Improvement(1), Sport Activities and Apparels(2), Tarots(1)
Showing topics: 1, 10
Available total: 448
View only a list of the snippets by this author: click here.
Other topics available for this author: click on any title below to view the complete item:
Maria Angelillo: I Mantra. Citazioni Preferite E Commento Identification Number: 451 Visitors: 7,108 Oscar Wilde: The Soul Of Man (Under Socialism): Part 2 Identification Number: 450 Visitors: 6,964 Oscar Wilde: The Soul Of Man (Under Socialism): Part 1 Identification Number: 449 Visitors: 6,301 Friedrich Schiller: Detached Reflections On Different Questions Of Aesthetics Identification Number: 448 Visitors: 7,050 Friedrich Schiller: Reflections On The Use Of The Vulgar Elements In Art Works Identification Number: 447 Visitors: 6,639 Friedrich Schiller: Of The Cause Of The Pleasure We Derive From Tragic Objects Identification Number: 446 Visitors: 5,702 Friedrich Schiller: On The Tragic Art Identification Number: 445 Visitors: 6,044 Rainer Maria Rilke: Lettere A Un Giovane Poeta. Citazioni Preferite In Italiano Identification Number: 441 Visitors: 8,372 Ananda K. Coomaraswamy: La Danza Di Siva: Citazioni Preferite In Italiano Identification Number: 439 Visitors: 6,899 Alberto Savinio: Maupassant E "L' Altro". Citazioni Preferite. Identification Number: 434 Visitors: 9,793
External services
This page of this subscriber uses external services: Hide