/    Sign up×
Community /Pin to ProfileBookmark

I use Xampp to write/test codes before uploading to hosted server. Unfortunately my hosted server uses an older version of PHP (5.2.17) than Xampp (PHP Version 5.4.7).

I need to accomplish the below using the PHP version of my hosted server since “diff” isn’t available.

[code=php]
$todaydate = new DateTime();
$todaydate->setDate($year, $month, $day);
$todaydate->setTime(11, 15);

// Calculate number of days, months and years between today’s date and rental date
$rentdate = new DateTime($rentaldate);
$rinterval = $rentdate->diff($todaydate);
$ryears = $rinterval->format(‘%y’);
$rmonths = $rinterval->format(‘%m’);
$rdays = $rinterval->format(‘%d’);[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 16.2014 — Only way I can think of within native PHP is to use timestamps (e.g. from time() and strtotime()), get the difference (in seconds), then divide by seconds per day to get number of days, etc.; but that gets ugly sometimes with leap years, daylight savings time, and so forth. If that's not acceptable and no one comes up with something better, (maybe something from the PEAR repository?), you might be able to leverage your DBMS via a query (that doesn't even need to reference a DB table).
Copy linkTweet thisAlerts:
@Alan_PauthorNov 16.2014 — I think the best thing for me to do here is to get another hosting account and ask them to install PHP 5.3 or greater. I have several websites on my current hosting account and many of those use older code such as mysql instead of mysqli or OOP and upping the PHP version on it may cause problems. It'll cost me more but it'll be easier keeping my current code than coming up with an alternative to using diff().

Thanks.
Copy linkTweet thisAlerts:
@NogDogNov 16.2014 — I think the best thing for me to do here is to get another hosting account and ask them to install PHP 5.3 or greater. I have several websites on my current hosting account and many of those use older code such as mysql instead of mysqli or OOP and upping the PHP version on it may cause problems. It'll cost me more but it'll be easier keeping my current code than coming up with an alternative to using diff().

Thanks.[/QUOTE]


All in all, definitely the best solution, I think. ?
×

Success!

Help @Alan_P 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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