Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Displaying a date difference

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #42797
    Kralle
    Participant

    Hello beautiful people.

    I’m searching for a way to display a difference between two dates using PHP. I want it to output “X days ago” whereas the X will be the number.

    I have an array where I put the date:


    $pictures = array(
    array(
    'title' => "Mount Everest",
    'filename' => "everest.jpg",
    'upload_date' => "14-02-2013"
    )
    );
    ?>

    I want to target the ‘upload_date’ and find the difference between that date and now. I was thinking that I could do something like this:


    $today = time(); // Get the current time
    $uploaded = strtotime($pictures); // Convert the date to a timestamp

    $days_ago = ($today - $uploaded) / 60 / 60 / 24; // Subtract the date from the current time and display as days

    … but it turns out that there is an Undefined index: upload_date. I just can’t seem to figure out what’s wrong with the code.

    Thanks in advance,
    Kralle

    #125456
    Kralle
    Participant

    Thanks a lot for your help, sir! That worked out pretty well.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.