Solved

Finding days between date and a timestamp

Posted on 2007-11-24
6
217 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
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!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

617 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