WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : how can I output the difference between two dates?
Categories : Date Time, PHP Update Picture
Colin Viebrock
Date : May 29th 1998
Grade : 3 of 5 (graded 1 times)
Viewed : 11210
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Colin Viebrock
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
$date1=mktime($hour1,$minute1,$second1,$month1,$day1,$year1);
$date2=mktime($hour2,$minute2,$second2,$month2,$day2,$year2);
$diff_in_secs=$date2 - $date1;
$diff_in_days=$diff_in_secs / 86400;
?>



If you want to create select buttons featuring current date this example will show you how...
Categories : Date Time, HTML and PHP, PHP
Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used.
Categories : HTML and PHP, PHP, Date Time
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
Count Number Of weeks in Month
Categories : PHP, Date Time, Beginner Guides
table calendar pretty much does what cal(1) does - prints out a calendar.
Categories : Date Time, PHP, Calendar
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
Calendar class on the same page , suitable for reservation
Categories : PHP, Calendar, Date Time
Date Validation using JavaScript. Intended to use it as checkdate() from PHP.
Categories : Java Script, Date Time, PHP
Calendars to choose a range of dates , reservation events ...
Categories : PHP, Calendar, Java Script, Date Time
CALENDAR - easy calendar-navigation with PHP
Categories : PHP, Date Time, HTML and PHP, Calendar
a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes
Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays.
Categories : Calendar, Date Time, PHP, Databases, MySQL
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
Local-to-user date and time display regardless of time zone or where the website's server is located
Categories : PHP, Date Time, HTML and PHP, Java Script
 Yared wrote : 467
function get_day_diff($date_1, $date_2) 

    /*=================================================================   
            Requires:     date_1 to be greater than date_2
        Description:  This will return the difference in days 
                                          between two PHP timestamps 
    ===================================================================*/ 
        $day_diff = ($date_1 - $date_2) / 86400;  
        return($day_diff); 
                 
} // end get_day_diff
 
 Yared wrote : 468
Use this function to get the timestamp

function get_timestamp($date) 

    /* =================================== 
        Require: 
    date to be YYYY-MM-DD format
        Description"
    Take a date in YYYY-MM-DD format and return 
                it to the user in a PHP timestamp 
      
    =============================== Yared*/ 
    // split the array
    $date_array = explode("-",$date);  
     
    $year = $date_array[0]; 
    $month = $date_array[1]; 
    $day = $date_array[2]; 

    $timestamp = mktime(0,0,0,$month,$day,$year); 
    return($timestamp); // return it to the user 
}
 
 Christian Seip wrote : 570
Change 

$diff_in_secs=$date2-$date1;

to 

$diff_in_secs=abs($date1-$date2);

and you don`t need to care anymore which of both dates is greater.
 
 chris christodoulou wrote :721

&lt;? 
$today = date("d m y");
$week = date("d m Y",time() + 604800); //604800 is 7 days from today (24 hrs * (60min * 60sec)) * 7 days = 604800 
$difference = $week - $today;
echo"Today is: $today&lt;br&gt;";
echo"Tomorrow: $week&lt;br&gt;";
echo"$difference";
//simple and working

?&gt;