Solved

Finding days between date and a timestamp

Posted on 2007-11-24
210 Views
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
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
• 2
• 2
• 2

LVL 20

Accepted Solution

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

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

Author Comment

ID: 20343984
Sorry steelseth12,

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

So what it should be the rest?
0

LVL 20

Expert Comment

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

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

:P
0

Author Comment

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

Featured Post

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.