/    Sign up×
Community /Pin to ProfileBookmark

Trouble with date calculation

I am trying to do a date test on values coming back from an MySql database…here is my code…

while ($row = mysql_fetch_array($result))
{
$signUpDate = date(“m/d/Y”,strtotime($row[‘signupdate’]));
$lastLeadDate = date(“m/d/Y”,strtotime($row[‘lastleaddate’]));
$dateDiff = $signUpDate – $lastLeadDate;
$fullDays = floor($dateDiff/(60*60*24));
echo “<br/>”;
echo $signUpDate ;
echo “<br/>”;
echo $lastLeadDate;
echo “<br/>”;
echo $dateDiff;
echo “<br/>”;
echo $fullDays;

}

here is my results

06/08/2010
01/01/2011
5

I am not sure why I am getting the “5” which I assume is the diff in months

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Jan 09.2011 — You can take care of these calculations inside of the query.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Otherwise you need to be more specific about what you're trying to do. It seems odd to me to try and express a difference in dates using a date format... Maybe just the difference in days would be better?

[CODE]SELECT
signupdate,
lastleaddate,
TIMESTAMPDIFF(DAY,signupdate,lastleaddate) as fullDays
FROM yourtable[/CODE]
×

Success!

Help @psdeveloper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...