Solved

Finding days between date and a timestamp

Posted on 2007-11-24
6
210 Views
Last Modified: 2008-02-01
I have a problem with date,

I have 2 variables:
$timestamp = mktime(0,0,0,date("m"),date("d"),date("Y"));
and a $date which is 11-22 05:50:00

I am trying to find how many days between them? I tried below:

<?php echo "($timestamp - $date)"; ?> But this is giving the strings like below:

11958804002007 - 11-22 05:50:00

How can I find how many days between them?

Thank you,
0
Comment
Question by:cemlouis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 250 total points
ID: 20343946
$timestamp = mktime(0,0,0,date("m"),date("d"),date("Y"));

$date = "11-22 05:50:00";

$date = strtotime(date("Y")."-".$date);

$sec =  $timestamp - $date;


$days = ceil($sec / 86400);

print $days;
0
 
LVL 17

Expert Comment

by:nplib
ID: 20343975
$timestamp = mktime(0,0,0,date("m"),date("d"),date("Y"));
$unc = strtotime($date);
$days = number_format($timestamp - $unc);
0
 

Author Comment

by:cemlouis
ID: 20343984
Sorry steelseth12,

The date was $date = "2007-11-22 05:50:00"; my mistake.

So what it should be the rest?
0
Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

 
LVL 20

Expert Comment

by:steelseth12
ID: 20343990
In that case we dont need to add the year so ...

$timestamp = mktime(0,0,0,date("m"),date("d"),date("Y"));

$date = "2007-11-22 05:50:00";

$date = strtotime($date);

$sec =  $timestamp - $date;


$days = ceil($sec / 86400);

print $days;
0
 
LVL 17

Expert Comment

by:nplib
ID: 20343995
crap, I forgot that it does it in seconds and not days.

:P
0
 

Author Comment

by:cemlouis
ID: 20344012
Thanks all it is done...
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

751 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