Solved

Finding days between date and a timestamp

Posted on 2007-11-24
6
199 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 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