Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 814
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Re: PHP Time block

Started by FireDitto, October 19, 2016, 12:25:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FireDitto

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

emanuele

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?

FireDitto

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

emanuele

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. :)

FireDitto