SHARE
TWEET

get hours, days, from two differents dates. PHP

AroliS Jun 25th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ================================================ v0.1 ============================================
  2.  
  3. <?php
  4. function GetTimeFormat( $actual_date, $last_join )
  5. {
  6. $pDate = new DateTime('2019-11-30 03:55:06'); // actual date
  7. $sDate = new DateTime('2019-11-30 11:55:06'); //last join
  8.  
  9. $aTime = $pDate -> diff( $sDate );
  10.  
  11. $aYears = $aTime -> format('%Y');
  12. $aMonths = $aTime -> format('%m');
  13. $aDays = $aTime -> format('%d');
  14. $aHour = $aTime -> format('%H');
  15. $aMin = $aTime -> format('%i');
  16. $aSec = $aTime -> format('%s');
  17.  
  18. if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 && $aHour == 0 && $aMin == 0 ) $time = 'few secs.';
  19. else if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 && $aHour == 0 ) $time = $aMin . ' minutes.';
  20. else if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 ) $time = $aHour . ' hours and ' . $aMin . ' minutes.';
  21. else if ( $aYears == 00 && $aMonths == 0 ) $time = $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
  22. else if ( $aYears == 00 ) $time = $aMonths . ' months, ' . $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
  23. else  $time = $aYears . ' years, ' . $aMonths . ' months, ' . $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
  24. echo $time;
  25.  
  26. //output 09 hours and 0 minutes
  27. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top