Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================================================ v0.1 ============================================
- <?php
- function GetTimeFormat( $actual_date, $last_join )
- {
- $pDate = new DateTime('2019-11-30 03:55:06'); // actual date
- $sDate = new DateTime('2019-11-30 11:55:06'); //last join
- $aTime = $pDate -> diff( $sDate );
- $aYears = $aTime -> format('%Y');
- $aMonths = $aTime -> format('%m');
- $aDays = $aTime -> format('%d');
- $aHour = $aTime -> format('%H');
- $aMin = $aTime -> format('%i');
- $aSec = $aTime -> format('%s');
- if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 && $aHour == 0 && $aMin == 0 ) $time = 'few secs.';
- else if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 && $aHour == 0 ) $time = $aMin . ' minutes.';
- else if ( $aYears == 00 && $aMonths == 0 && $aDays == 0 ) $time = $aHour . ' hours and ' . $aMin . ' minutes.';
- else if ( $aYears == 00 && $aMonths == 0 ) $time = $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
- else if ( $aYears == 00 ) $time = $aMonths . ' months, ' . $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
- else $time = $aYears . ' years, ' . $aMonths . ' months, ' . $aDays . ' days, ' . $aHour . ' hours and ' . $aMin . ' minutes';
- echo $time;
- //output 09 hours and 0 minutes
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement