Solved

Getting How Many Days Have Past Since a Certain Date

Posted on 2009-05-18
8
1,457 Views
Last Modified: 2013-12-12
I need a simple function that will get the number of days that have past since a certain date.

For example:

Start date is 04/14/09 and it's stored in my DB in that format ("m/d/Y")
End date is TODAY or date("m/d/Y") - 05/18/09

$start = strtotime($date_joined);
$end = strtotime($today);
$days_past = {THIS IS WHAT I NEED TO KNOW}

How would I find out how many days have past since the start date?

All my dates are in the format of m/d/Y so I imagine I'd have to use strtotime right?

Please provide me a function that will accomplish this...I've looked and looked but cannot find anything that works.
0
Comment
Question by:Jeff Long
  • 4
  • 3
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24413208
you might start off here:
http://www.addedbytes.com/php/php-datediff-function
watch out to implement the improvements!
0
 

Author Comment

by:Jeff Long
ID: 24413499
Sorry but that was not helpful and too confusing...someone else please help. Thanks.
0
 
LVL 5

Accepted Solution

by:
bored321 earned 500 total points
ID: 24413597
This should work.
<?php
$start = strtotime($date_joined);
$end = strtotime($today);
 
$timediff = $end-$start; //difference in seconds
 
$days_past = $timediff/(60*60*24); //convert to days
 
?>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Jeff Long
ID: 31582643
Thank you for not being lazy and providing me the exact function I needed. It worked perfectly!
0
 

Author Comment

by:Jeff Long
ID: 24413672
bored321,

Thank you for providing me such a clear and direct solution to my problem.

It worked perfectly.

I knew it had to be WAY easier than that whirlwind of nonsense angelll sent me to.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24414654
Hi,

>Thank you for not being lazy and providing me the exact function I needed. It worked perfectly!
just to explain why I posted the link, and not the exact function:
* the function shall be helpful in many situations in your near and far future.
* you claim me to be lazy, but you don't seem to know me...
* if I posted "helpful" links, so you can work out your solution, is better for you, as this chinese proverb goes:
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.

CHeers
0
 

Author Comment

by:Jeff Long
ID: 24414772
Yeah that wasn't kind of me...I apologize :)

I'm sure you not lazy.  Thanks for wanting to help me I just couldn't make heads or tails of the solution you provided.

God Bless!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24414833
no harm done.
CHeers
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Dork query 7 62
Put POST values into cookies. 14 32
Compiling PHP with Curl plus protocols 8 21
Displaying a google org chart from php/mysql code 27 18
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question