/    Sign up×
Community /Pin to ProfileBookmark

days difference between 2 timestamps

i have 2 time stamp values
and i want to subtract them
then i want to extract the difference of days between them by date(“d”,$new_ts)
but if the subtract result is 0 i get 31 from the date function ??
how to do it ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 02.2008 — That's because a PHP time value is the number of seconds since January 1 1970 00:00:00 GMT. If your server's time zone is west of the GMT zone, then 0 will be interpreted as December 31 1969, thus the result of "31" for the day in the date() function.

The quick-and-dirty solution is to divide the difference by 60*60*24, rounding up or down as applicable to your purposes (see the ceil(), floor() and round() functions).
×

Success!

Help @sakherq 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...