function to show date passed after posts publish
-
hello guys
i create a function to show how many days or months or years passed after posts published but its not work, what im done wrong?<?php if( !function_exists('property_published_date') ) { function property_published_date(){ $publish_date = the_date('Ymd','','',false); $current_date = date_i18n('Ymd'); ?> <div class=property-published-date> <?php _e('Registration date of the property: ','inspiry'); if (!empty($publish_date)){ $years = substr($publish_date,0,4);$months = substr($publish_date,4,2);$days = substr($publish_date,6,2); $property_published_date = "$years/$months/$days"; echo $property_published_date; } if (empty($publish_date)) { _e(' (Unknown)','inspiry'); }else{ $c_years = substr($current_date,0,4);$c_months = substr($current_date,4,2);$c_days = substr($current_date,6,2); $yearsresult = $years - $c_years; $monthsresult = $months - $c_months; $daysresult = $days - $c_days; if ($yearsresult == 0 && $monthsresult == 0 && $daysresult == 0){ _e(' (Today)','inspiry'); }elseif($yearsresult == 0 && $monthsresult == 0 && $daysresult < 31){ if ($daysresult < 7 and $daysresult > 1){ _e(' (less than a week)','inspiry'); }elseif ($daysresult > 7 and $daysresult < 14){ _e(' (less than two weeks)','inspiry'); }elseif ($daysresult == 14){ _e(' (two weaks ago)','inspiry'); }elseif ($daysresult > 14 && $daysresult < 21){ _e(' (more than two weeks)','inspiry'); }elseif ($daysresult == 21){ _e(' (three weeks ago)','inspiry'); }elseif($daysresult > 21 && $daysresult < 28){ _e(' (more than three weeks)','inspiry'); }elseif($daysresult >= 28 ){ _e(' (more than four weeks)','inspiry'); } }elseif($yearsresult == 0 && $monthsresult < 12){ if ($monthsresult == 1){ _e(' (one month ago)','inspiry'); }elseif($monthsresult == 2){ _e(' (two months ago)','inspiry'); }elseif($monthsresult == 3){ _e(' (three months ago)','inspiry'); }elseif($monthsresult > 3 && $monthsresult < 6){ _e(' (more than three months)','inspiry'); }elseif($monthsresult == 6){ _e(' (six months ago)','inspiry'); }elseif($monthsresult < 9 && $monthsresult > 6){ _e(' (more than six months)','inspiry'); }elseif($monthsresult == 9){ _e(' (nine months ago)','inspiry'); }elseif($monthsresult > 9){ _e(' (more than nine months ago)','inspiry'); } }elseif($yearsresult > 1){ if ($yearsresult == 1){ _e(' (one year ago)','inspiry'); }elseif($yearsresult == 2){ _e(' (two years ago)','inspiry'); }elseif($yearsresult == 3){ _e(' (three years ago)','inspiry'); }elseif($yearsresult > 3){ _e(' (more than three years ago)','inspiry'); } } } ?> </div> <?php } }
Thanks in advanced!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘function to show date passed after posts publish’ is closed to new replies.