SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Please help ... php minutes counter

    Hi, anyone,

    I have this code:

    Code:
    <?php
    
    $date1 = "2007-03-24";
    $date2 = date('Y-m-d');
    
    $diff = abs(strtotime($date2) - strtotime($date1));
    
    $years = floor($diff / (365*60*60*24));
    $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
    
    printf("%d years, %d months, %d days\n", $years, $months, $days);
    
    ?>
    But i want to add hours, minutes and secundes.

    Can you help me ? I simply cant do it.

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, great. Just for 2 code lines I need an account.

    That's great ! Thank you.

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,401
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    You don't need 3rd party code to do that, PHP has built-in classes that can handle the job:
    PHP Code:
    $date1 = new DateTime("2007-03-24");
    $date2 = new DateTime();

    $diff $date2->diff($date1);

    printf("%d years, %d months, %d days, %d hours, %d minutes, %d seconds\n"$diff->y$diff->m$diff->d$diff->h$diff->i$diff->s); 

  5. #5
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you very much, fretburner !
    The code work like a charm and I am very happy to see that.
    Thank you again !


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •