Solved

Finding days between date and a timestamp

Posted on 2007-11-24
6
190 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cookies analysis tools 2 29
Paging Using PHP 7 34
Change password through link 1 13
PHP JSON Clean up 5 10
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:

746 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

13 Experts available now in Live!

Get 1:1 Help Now