School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,368 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,450 people online right now. Registration is fast and FREE... Join Now!




Find Days Between 2 Dates

 
Reply to this topicStart new topic

> Find Days Between 2 Dates

noorahmad
Group Icon



post 27 May, 2009 - 11:31 PM
Post #1


Day Different Between 2 Dates

one of the problems that i was facing was time and date difference in PHP and saw here are many users that they want date difference between 2 date so in tutorial i'm going to show how to get days between 2 date.
i am using PHP 5+ and the following function please read these function before reading this tutorial.

gregoriantojd
Parameters:
month Month of the Year
day Day of the Month
year Year

explode
explode use for array to create an array of given value or string
example:
CODE

$explod = explode(" ","this is a sample text");
echo $explod[3];//our put sample
//or we can use an loop for printing value of array

separator a string separator value exmaple "/" or "-" or " " or any thing you want
string the string value to search and cut by separator value
limit optional maximum length

ok lets start:
here i am changing the date format for gregoriantojd, because i'm using "dd-mm-yyyy" format in my example and if we explode it, the value of array changing to (0) for day, (1) for month, (2) for year and gregoriantojd is asking first for month, day and year.

first create a function.
CODE
function MyDate($explod,$startDate,$endDate)
{
$d1  = explode($explod,$startDate);
$d12 = gregoriantojd($d1[1],$d1[0],$d1[2]);
$d2  = explode($explod,$endDate);
$d22 = gregoriantojd($d2[1],$d1[0],$d1[2]);
$diff = $d22 - $d12;
return $diff;
}



how to use it

CODE

$sdate = "1/1/2009";
$edate = date('d/m/Y');
echo myDate("/",$sdate,$edate); //out put is 120

Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 08:54PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month