• I was trying to display a single number that shows how many days our organization has been established.

    e.g. assume we started at 5/12/2014, and it will shows “2” today. If I visit it on tmr, 5/14/2014, it will show “3”.

    can this be solved by a short piece of php or html?

    thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this:

    $date_one = new DateTime("2014-05-12");
    $date_two = new DateTime("now");
    $daydiff = $date_one->diff($date_two);
    if ($daydiff->days == 1) {
        $my_day = " day.";
    } else {
        $my_day = " days.";
    }
    echo "We've been established for " . $daydiff->days . $my_day;
    Thread Starter Uduse

    (@uduse)

    Thanks a lot.

    Though I know nothing about php, here’s my try:

    <html>
      <div align="center">
      We have been here for
      <br/>
      <br/>
      <br/>
      <?php
        date_default_timezone_set('America/Los_Angeles');
        $date_one = new DateTime("2014-03-05");
        $date_two = new DateTime("now");
        $daydiff = date_diff($date_one, $date_two);
        echo $daydiff->days;
      ?>
      <br/>
      <br/>
      days
      </div>
    </html>

    it works on online version of php ( like this one https://www.compileonline.com/execute_php_online.php )

    but it doesn’t work on my blog.

    the display on my blog is like this:

    We have been here for 
    
    days; ?> 
    
    days

    any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add a simple number that shows how many days has passed?’ is closed to new replies.