Created
October 8, 2020 21:12
-
-
Save FerFuego/dcec26a8f75d7776b61538331a873d14 to your computer and use it in GitHub Desktop.
Calc time to posted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return time to posted | |
*/ | |
function time_to_post($post = null) { | |
$current_day = date('Y-m-d h:i'); | |
$post_day = ( $post ) ? get_the_time('Y-m-d h:i', $post) : get_the_time('Y-m-d h:i'); | |
$s_time = strtotime($current_day) - strtotime($post_day); | |
$m_time = intval($s_time/60); | |
$h_time = intval($s_time/3600); | |
$d_time = intval($s_time/86400); | |
if ($m_time < 1 ) { | |
$time = 'Few seconds ago'; | |
} else { | |
if ($h_time < 1 ) { | |
$time = 'Few minuts ago'; | |
} else { | |
if ($h_time == 1 ) { | |
$time = $h_time.' hour ago'; | |
} else { | |
if ( $h_time > 24 ) { | |
$day = intval($h_time / 24); | |
if ( $day == 1 ) { | |
$time = $day . ' day ago'; | |
} else { | |
if ( $d_time > 30 ) { | |
$mount = intval($d_time / 30); | |
if ( $mount == 1 ) { | |
$time = $mount . ' month ago'; | |
} else { | |
$time = $mount . ' months ago'; | |
} | |
} else { | |
$time = $d_time.' days ago'; | |
} | |
} | |
} else { | |
$time = $h_time.' hours ago'; | |
} | |
} | |
} | |
} | |
return $time; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment