days between two given dates using PHP

days between two given dates using PHP

How can we know the number of days between two given dates using PHP?

View Answers

December 27, 2010 at 12:54 PM

Hi friends,    

Example: 

    <html>
    <head>
    <title>Number of days between two dates. </title>
    </head>
    <body>
    <?php
    /* Date format*/
    $dateFormat="Y-m-d";
    // Current date 
    $date1=Date($dateFormat);
     echo "<br>First date : ".$date1."<br>"; 
     // Another date
    $date2="2010-12-25";
     echo "Second date : ".$date2."<br>"; 
     // Number of days in between to given date in php
    $days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
    echo "Number of days : ".$days;
    ?>
    </body>
    </html>

Thanks.









Related Tutorials/Questions & Answers:
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example...;"; // Number of days in between to given date in php $days = (strtotime
How can we know the number of days between two given dates using PHP?
How can we know the number of days between two given dates using PHP?  How can we know the number of days between two given dates using PHP
Advertisements
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need... using Date.getTime() function. Once both Dates have been converted, subtracting
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
Java get number of days between dates
the number of days between the two described dates. In order to get the number of days between two dates, the given example has set two dates by using... returns the number of days between two dates:ADS_TO_REPLACE_2
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Hi .Difference between two Dates - Java Beginners
between two dates.. I need to display the number of days by Each Month...Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very..., 1); cal2.set(2008, 9, 31); System.out.println("Days= "+daysBetween
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
PHP and MySQL BETWEEN dates with different years
PHP and MySQL BETWEEN dates with different years  I have a database... they should only show on the site when the date chosen falls between those dates. I thought it made sense to make use of the SQL BETWEEN statement, but it does
mysql between dates not between dates
mysql between dates not between dates  I am trying to list the data between dates and not between dates using join method ..but that not working for me
display diffrence between two dates in a text box - JSP-Servlet
display diffrence between two dates in a text box  i have these set...); int days=(int)((ed.getTime()-sd.getTime())/(1000*60*60*24)); // i need to print the days in another text box when i click inside that test box.lease help me
to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write a function which calculates the difference between 2 different dates 1.The function should accept 2 different dates (in the format dd/mm/yyyy hh:mm:ss AM/PM) 2.The
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two dates from the database table. I am using combo box to get the date. Problem
Comparing two Dates in Java
Comparing two Dates in Java   ... using java.util.Date class. For comparing dates, we will be using compareTo... dates using compareTo() method.ADS_TO_REPLACE_1 firstDate.compareDate
Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA... the difference between two dates. public class DateDiffDemo { public static...Difference in two dates  Hello there once again........ Dear Sir
PHP Date compare the dates, PHP Compare dates example
to compare two difference dates in PHP echo "<b>PHP Date compare... The PHP Date compare the dates example code In this PHP Compare dates example, we are describing the code to compare the dates. In the php program we have
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
Comparing two dates in java
Comparing two dates in java In this example you will learn how to compare two dates in java.  java.util.Date provide a  method to compare two dates... date. The example below compares the two dates. import
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
php two dimensional array
php two dimensional array  php two dimensional array example
Annotations are using now a days?
Annotations are using now a days?  i have a doubt in Annatation, if we use Annatation we must hardcoding the code/data but sunmicrosystem itself says that hardcoding is not recommended
Comparing Dates in Java
two given dates. To compare dates the given program is helpful for application... Comparing Dates in Java       This example illustrates you how to compare two dates. Generally dates
To get the String between two strings
To get the String between two strings  How to get string between two strings repeatedly using java?   Hi, Please tell me more about what do you want to achive.ADS_TO_REPLACE_1 Thanks
PHP convert week number to days or month - PHP
PHP convert week number to days or month  Small, simple and easy code that can do following task: 1.Convert Week Numbers to Month 2.Convert Week to Date Generally, we use the date time object in PHP to convert the date
Two Dates code validation - Date Calendar
Two Dates code validation  Hi Sir.I am using calender for two text... dates."); datefield.focus(); return false; } else { return true...(date2.value)) { alert("The dates are valid."); } else { if (date1.value
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing two dates. In  this example we are going to compare two date objects
combine two arrays in php
combine two arrays in php  combine two arrays in php   $newArray = array_combine($diff, $pages_name['data']); foreach ($newArray as $data) { var_dump($data); exit('zzzzz'); echo $data . '<br>
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
java collision detection between two images
java collision detection between two images  java collision detection between two images
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
PHP Date add days
In this example we will create sample code to add days or weeks... <?php $currentDate = date("Y-m-d");// current ...;adding 30 days: ".date('l dS \o\f F Y
urgent need in two days - JSP-Servlet
understand the Mysql and Jdbc database connectivity code  understand the Mysql and Jdbc database connectivity code through example.  See the Given JSP Example Code-------------------------------Servletform.html<
php include and require
php include and require       In php include and require are almost same but the difference between these two..._TO_REPLACE_1 In the following examples we will see how these two statements include
PHP Variables between Scripts
PHP Variables Between Scripts As you know how to define variables and how to use them in your form. Now, we learn how to use  PHP variables between scripts. It is quite similar as using variable in a normal manner. Let see
how to get string between two characters
how to get string between two characters  hgow to get string from between two characters. ex:[email protected] from the above word i want a string between characters . and @ send the required method and give better example
validation on dates - Java Beginners
validation on dates  how to find difference in days between two dates in java.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/java-get-example/number-days-between.shtml Thanks
How to manage cookie in between two JSP Pages
How to manage cookie in between two JSP Pages  How to manage cookie in between two JSP Pages   you can set cookies in response object e.g.response.addCookie(new Cookie("userName","Password")). Chandraprakash Sarathe
Date Difference
; This example learns how to make the difference between two dates and how... into days. Here we are using Calendar, an abstract base class that extends Object class and makes a difference between a Date object and a set of integer
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
IF - PHP If and else Statement
IF - PHP If and else Statement in PHP “IF” is a conditional statement that gives the opportunity to choose between two values. It can also... statement.  Apart from PHP there are many more programming languages that too
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
upload video using php
upload video using php  How to upload a video on MYSQL Server using PHP Code..? Can any one provide me an example
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two
Java Swing Date Difference
the difference between two dates. Here is an example that accepts two dates from... in the format dd-MM-yyyy using the SimpleDateFormat class. We have created the following method that calculates the date difference in terms of days

Ads