php - Get only days ago the node was posted - Drupal 7 -


how can days ago node posted?

e.g. if node post date yesterday print "1" or node post date 1 month , 1 week ago print "37"

i trying solve using following snippet failed

<?php echo 'posted: ',format_interval(time()-$node->created); ?> 

format_interval() function formats time interval requested granularity.

for example if current unix time 1427868018 , node created time 1366045256:

  • format_interval((time() - $node->created) , 1)) returns "1 year",
  • format_interval((time() - $node->created) , 2)) returns "1 year 11 months",
  • format_interval((time() - $node->created) , 3)) returns "1 year 11 months 2 weeks",
  • format_interval((time() - $node->created) , 4)) returns "1 year 11 months 2 weeks 6 days".

if want display days, can use following code:

$intervalseconds = time() - $node->created; $intervaldays = floor($intervalseconds / 86400);  print $intervaldays;  if ($intervaldays == 1) {     print ' day'; } else {     print ' days'; } 

it return "715 days".


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -