Solved

Finding days between date and a timestamp

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form not operating correctly. 1 22
test if query has no results 2 19
PHP get array item with custom id 4 21
using php variable inside javascript 5 13
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
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…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now