<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Subesh Pokhrel&#039;s Blog - Magento Development Tips &#187; time function</title>
	<atom:link href="http://subesh.com.np/tag/time-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://subesh.com.np</link>
	<description>PHP &#38; Magento Tips and Tutorials</description>
	<lastBuildDate>Wed, 01 Feb 2012 04:09:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Calculating the difference between timestamps in PHP</title>
		<link>http://subesh.com.np/2008/06/calculating-the-difference-between-timestamps-in-php/</link>
		<comments>http://subesh.com.np/2008/06/calculating-the-difference-between-timestamps-in-php/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 10:45:12 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[time function]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=22</guid>
		<description><![CDATA[Most of us, programmer have conditions of calculating the difference between timestamps, i.e the difference between now and the timestamp from mysql result. The logic for this is pretty simple. Just convert the two timestamps to Unix time format and take the difference between the two. Next convert the difference into corresponding days,hour,minutes or in [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us, programmer have conditions of calculating the difference between timestamps, i.e the difference between now and the timestamp from mysql result. The logic for this is pretty simple. Just convert the two timestamps to Unix time format and take the difference between the two. Next convert the difference into corresponding days,hour,minutes or in any unit you want to.</p>
<p>Here&#8217;s the source code for finding out the difference between two timestamps.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function expiredTime($expdate){
       $temp1=explode(&quot; &quot;,$expdate);
       $temp=explode(&quot;-&quot;,$temp1[0]);
       $year = $temp[0];
       $month= $temp[1];
       $day = $temp[2];
       $hour = '00';
       $minute = '00';
       $second = '00';
       list($dl,$hl,$ml,$sl) = countdown($year, $month, $day, $hour,$minute, $second);
       return $dl.&quot;days &quot;. $hl.&quot;hr &quot;.$ml.&quot;min &quot;.$sl.&quot;sec&quot;;
}
?&gt;
</pre>
<pre class="brush: php; title: ; notranslate">
&lt;?php
 function countdown($year, $month, $day, $hour, $minute, $second)
               {
                 global $return;
                 global $countdown_date;
                 $countdown_date = mktime($hour, $minute, $second, $month, $day, $year);
                 $today = time();
                $diff = $countdown_date - $today;
                 if ($diff &lt; 0)$diff = 0;
                 $dl = floor($diff/60/60/24);
                 $hl = floor(($diff - $dl*60*60*24)/60/60);
                 $ml = floor(($diff - $dl*60*60*24 - $hl*60*60)/60);
                 $sl = floor(($diff - $dl*60*60*24 - $hl*60*60 - $ml*60));
               // OUTPUT
               $return = array($dl, $hl, $ml, $sl);
               return $return;
               }

?&gt;
</pre>
<p>There are two functions here expiredTime ( ) and countdown ( ). The input for the expiredTime is the timestamp from the mysql result. This function evaluates the value of year,month,hour,minutes and seconds of the input parameter and then calls the next function countdown ( ), with those evaluated values as inputs.</p>
<p>The countdown function then calculates the time now and the difference <strong>code block 2 #08</strong>. Then the difference is divided accordingly, with appropriate denominators to find out the days,hour,minutes,seconds passed the input time, untill now. <strong>Code block 2 #10-13</strong> is simple mathematics. This function then returns the difference value in days,hour,minutes and seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2008/06/calculating-the-difference-between-timestamps-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

