I have a magazine blog that I am creating in Drupal 7. I have the date displayed in the upper right hand corner (JAN 2012). How could I have this display work dynamically based on the post date of the article shown or current month if on the main view (blog) landing page? Each blog landing page is a view so the content is filtered that way. I two custom content types to help filter content and custom field created on each as the publish date to push and pull content based on the month. I need to use that publish date field as the date. How do I tap into that field for the date I need?

1 Answer 1


You haven't explained the context of this date. Is it representing results coming out of views like "this post was 5 days ago" or do you just want todays date on the upper right?

This will print the current date on your theme template.

echo date('Y M D');

Share some more info on what this date is giving the user exactly; Drupal has some very helpful code for this kind of thing, such as format_date().

  • OK, I do just want to show the current day with the month abbreviated and the full year, but it would also be nice to follow the month of the current article shown so when in the archive the date change accordingly. Jan 1, 2012 at 19:45
  • Also the markup is separated with span tags with ids. One for month and one for year. Is it possible to breakup the php like: <span id="date_month"><?php echo date('M'); ?></span><span id="date_year"><?php echo date('Y'); ?></span> I need the output liek this: JAN 2012 Jan 1, 2012 at 19:49
  • format_date() looks like where I need to be looking but have no idea where or how to start. Any suggestions with the updated information? Jan 7, 2012 at 15:22
  • I am not sure what you mean did you test the example code? I assume you would be editing the theme template.tpl.php files maybe you are not? you can change the values in the echo from the values on the php website php.net/manual/en/function.date.php Start by testing that is some of what programming is all about ;)
    – imp
    Jan 7, 2012 at 15:47
  • Ah, yea I got the current date up just fine using what you gave but I would like to get a little deeper so able to show the date of the post, even when viewing the archive. Somehow the script communicates with the publish date field I created instead. Jan 8, 2012 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.