| <?php |
| |
| ############################################################### |
| # function getDateBefore($days) # |
| # # |
| # * returns the date from $days days before # |
| ############################################################### |
| |
| function getDateBefore($days){ |
| $oneWeek = time() - ($days * 24 * 60 * 60); |
| |
| return date('Ymd', $oneWeek); |
| } |
| |
| ############################################################### |
| # function convertNewsDate($date) # |
| # # |
| # * Transforms a news post date (NNTP-Posting-Date) into # |
| # YYYYMMDD format # |
| ############################################################### |
| function convertNewsDate($date){ |
| $months = array('Jan','Feb','Mar','Apr','May','Jun', |
| 'Jul','Aug','Sep','Oct','Nov','Dec'); |
| $i = 0; |
| |
| $parts = explode(" ",$date); |
| $day = (strlen($parts[0]) == 1)?"0".$parts[0]:$parts[0]; |
| $year = $parts[2]; |
| while($parts[1] != $months[$i++]); |
| $month = (strlen($i) == 1)?"0".$i:$i; |
| |
| return $year.$month.$day; |
| } |
| |
| function getUnixTimeStamp($date,$time){ |
| # Date info |
| $year = substr($date,0,4); |
| $month = substr($date,4,2); |
| $day = substr($date,6,2); |
| # Time info |
| $hour = substr($time,0,2); |
| $min = substr($time,3,2); |
| $sec = substr($time,6,2); |
| |
| return mktime($hour,$min,$sec,$month,$day,$year); |
| } |
| |
| function getUnixTimestampDiff($ts1,$ts2){ |
| return ($ts2 - $ts1); |
| } |
| |
| function realDate($timestamp){ |
| $rest = ($timestamp % 86400); |
| $days = ($timestamp - $rest) / 86400; |
| if ($days != 0) |
| $str = $days."d "; |
| $rest1 = ($rest % 3600); |
| $hours = ($rest - $rest1) / 3600; |
| if ($hours != 0 || $days != 0) |
| $str .= $hours."h "; |
| # $rest2 = ($rest1 % 60); |
| # $minutes = ($rest1 - $rest2) / 60; |
| # if ($minutes != 0 || $hours != 0) |
| # $str .= $minutes."m "; |
| # $seconds = $rest2; |
| # $str .= $seconds."s"; |
| |
| return $str; |
| } |
| |
| function getTimeDiff($date1,$date2){ |
| $y1 = substr($date1,0,4); |
| $m1 = substr($date1,4,2); |
| $d1 = substr($date1,6,2); |
| |
| $y2 = substr($date2,0,4); |
| $m2 = substr($date2,4,2); |
| $d2 = substr($date2,6,2); |
| |
| $date1 = mktime(0,0,0,$m1, $d1, $y1); |
| $date2 = mktime(0,0,0,$m2, $d2, $y2); |
| |
| $difference = $date2-$date1; |
| |
| return floor($difference/60/60/24); |
| } |
| |
| ?> |