Site visitors seeing your ugly error messages on the screen (along with details of your Drupal installation path)? Once your site goes from dev to launch, you probably want to have errors recorded in the log but not splashed across the screen. Head to the handy Error Reporting settings found at admin/settings/error-reporting.
How to display date and time?
How does one display the current date and time on a Drupal site?
Time for this newbie to take the plunge, and touch... oh, sweet mother of mercy... touch PHP!
A Drupal.org forum visitor asked about displaying the date and time on a site. I know there are countless ways to do this using web technologies, including any number of "widgets" available out there. For all I know, there may be a Drupal module that tosses up a block or something, too.
But I know this is the sort of task one can also do easily using PHP, the real guts of Drupal (well, part of the guts, anyway... maybe the pancreas). And it should be easy, too. So as a farewell to my... ahem... chastity with regards to PHP, let me take this oh-so-newbie challenge upon myself.
Google turns up all kinds of stuff. Like this couldn't-be-more-basic, one-size solution: http://www.totallyphp.co.uk/code/display_date_and_time_with_php.htm
Besides some code comments, there's just one line of key code there:
<?php echo date("l, F d, Y h:i" ,time()); ?>Let's try! I make a new block... turn off rich-text input (TinyMCE)... select PHP as my input format... and paste in the code. I save the block and make it display... and there it is, to the left! Stupendous!
Now, that's the barest of starts; I'll add more to this page as I play with more formatting and other options. (Like time zones: that's pretty important!) But wow, I'm now PHP-experienced and it didn't hurt at all. Before long I'll be up for CSS/HTML/PHP themeing three-ways til the break of dawn. Mmm, break out the mango love butter.
Relevant Content
The Drupal Ace logo has dealt these content suggestions from the deck.
- Working with Menus: Administration Form (Drupal 6)
- Drupal beginner documentation picking up steam
- Working with Menus: Administration Form (Drupal 5)
- Updating Easy Drupal Admin Manual
- Drupal for Beginners
- Why would Color-enabled themes work for all sites but one?
- Limiting node access: three quick'n'easy tools
Learn Drupal, hands-on
Get the beginner-friendly ebook that teaches community site building via a live case study.







okerytry ytr y tytryrt
okerytry ytr y tytryrt
Thank you!
Thanks for this. I was once afraid. Now, less so!
Re: How to display date and time?
Works beautifully.
I shortened up the code to only display the date, until I fugre how to account for time zones. But until then, this gets me there ;)
Thanks!
Post new comment