/    Sign up×
Community /Pin to ProfileBookmark

Date calculation help

Hi all

Using this code, I expect to see the $difference to be number 3 but it returns as 4 which is wrong:

[code=php]
$difference = strtotime(‘2010-04-01’) – strtotime(‘2010-04-03’);
echo $difference/(60*60*12);
[/code]

If I use this however (note the second date is 2010-04-02)

[code=php]
$difference = strtotime(‘2010-04-01’) – strtotime(‘2010-04-02’);
echo $difference/(60*60*12);
[/code]

$difference returns as 2 which is correct.

Why is this not working for the first calculation?

Thanks for helping

p.s. those who are wondering what I am trying to achieve, I just need to calculate the number of days difference between two dates!!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 28.2010 — I'm confused: you are dividing by 12 hours, but a day has 24 hours. Therefore the results make sense since there are two 12-hour increments per day, and in the first example you have a difference of 2 days multiplied by 2 12-hour periods per day.
×

Success!

Help @kbc1 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.19,
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,
)...