SimplePortal
Customization => Custom Coding => Topic started by: FireDitto on October 19, 2016, 12:25:49 PM
-
I have the following PHP in a block, which shows how long my forum has been running;
$time_diff = time() - strtotime("2012-01-06 04:01:43");
$tage = ($time_diff - $time_diff%86400)/86400;
$rest_zeit = $time_diff - $tage*86400;
$stunden = ($rest_zeit - $rest_zeit%3600)/3600;
$rest_zeit = $time_diff - $tage*86400 - $stunden*3600;
$minuten = ($rest_zeit - $rest_zeit%60)/60;
$rest_zeit = $time_diff - $tage*86400 - $stunden*3600 - $minuten*60;
$sekunden = $rest_zeit;
echo "<center>";
echo $tage." Days, ";
echo $stunden." Hours</center>";
And I love it, but I'd really like to make it roll over to years when it hits hte right number, rather than having thousands of days?
If anyone could help, I'd be grateful because I'm lost XD
-
I'm not sure I understood exactly what you want, sorry.
You want to show just the number of years instead of the number of days?
-
Sorry, I wasn't very clear I was in a rush to leave for work.
I'd like it to state;
Years, months, days - rather than - days, hours
-
Looking around, I'd say the easiest way is:
<?php
$datetime1 = new DateTime('2012-01-06 04:01:43');
$datetime2 = new DateTime(date('Y-m-d H:i:s'));
$interval = $datetime1->diff($datetime2);
echo '<center>';
echo $interval->format('%y Year %m Month %d Day %h Hours %i Minute %s Seconds');
echo '</center>';
Example from:
http://php.net/manual/en/datetime.diff.php
formatting from:
http://php.net/manual/en/function.date-diff.php#115065
Then you can adapt the format the way you want, and if you have doubts feel free to ask. :)
-
Thank you! :D
-
yw. :)