Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By 425Media on
Hello all,
I have looked around but could find a module that will display the data and time on the front page. Does anyone know of a good one? All I want is a little date and time listed near the top of the site.
Thanks for any pointers.
S
Comments
create custom block
create custom block .. with php code that shows date.. i think there is not any default functionality with Drupal to show date and time on Front Page.
Thanks!
Thanks kuldip. I will do that. It would be great if there was a module that did date and time tho. :)
S
It's easier to just create a
It's easier to just create a theme variable and then print this variable on the page template. I custom block will be overkill for a small task like this.
Eric
sollution
make your self an html block with the following, and place that block where ever you want.
^ O_o
I don't see creating a block to host the current date as an overkill; it's a perfectly legit use of Drupal's blocks, IMHO.
The simpler solution is to create a custom block that contains a simple call to Drupal's built-in
formate_date()
function. You just need to supply the PHP'stime()
function as its first argument. You may wrap all the code into a function to avoid name collisions, and of course you need to enable the PHP Filter module from the modules page. Paste the following code in the Body textarea, and use PHP code from the Input formats collapsible group:Give the block a name and description, and set it to show only on the front page using <front> as a value in the page specific visibility settings section.
Another approach as some has noted, is to use preprocess functions to add a variable to the page.tpl.php template and just print it where you would want in the template's code.
In both cases, using the Drupal's built-in and versatile
format_date()
allows you to customize the output of the date to your liking, make sure to consult the documentation and the API for instructions on how to leverage that function.Actually using a block could be more appropriate if you're using caching on your site and is concerned when the block or page (depends on which approach you use) is cached and thus does not display the correct current date.
The solution to this is to write a custom module that defines a block and set that block cache item to -1, which prevents caching the block even when caching on the website is turned on. Setting a block caching is not provided by the front-end block administration page in Drupal.
date and *time* was asked for
the problem with using php to display the time is that it doesn't update once the page has loaded. the javascript is going to auto-update itself and display the changing seconds even without the refresh. drupal is good for a great many things but displaying dynamic time isn't one of them.
Did the original poster ask
Did the original poster ask for dynamic date and time display on the second level? Even though, I'm pretty sure there are many elegant ways to do this using Drupal's powerful JavaScript features and jQuery.
Actually, Drupal allows to use its functions in JavaScript out of the box, so using JavaScript with
format_date()
should be quite easy to implement.To be honest I was just
To be honest I was just wondering if there was a module that could be added to my drupal sites that could provide a date and time service for my websites.
Thank you all for your suggestions, I will try to implement them and see what happens.
Thanks again.
S
subscribing
subscribing
Block containing time zone adjusted date and time
The Drupal date module must be installed for this to work. This solution uses functions which can be found in the file named "date_api.module" which is located under /sites/all/modules/date where the date module resides once installed. Look in that same file for info on formatting the date and time. The added advantage here is that it accounts for time zones if the user has selected one or defaults to the site's time zone if not. The downside is that it requires a page refresh to update the time.
I'm relatively new to PHP so I'm going to look into whether or not there's a PHP analog to the JavaScript SetInterval function as used by mannkoepke in his JavaScript offering above. If there is then that could be used with this code to take care of the dynamic updating. Perhaps a commingling of his JavaScript with this code?
Put the following code into a block and put wherever.
drupal timezone block
copy this into a block
use the link http://www.timeanddate.com/clocks/free.html?n=64
to choose your timezone and generate code automatically.
Just a quick note of caution
Just a quick note of caution not to use this code as it exists. "formate_date" is not a function! If you put this code in (as I did) without double checking it, it will break your site! The correct function call is format_date
"formate_date"
Hi mhalpern
I accidentally used the code with "formate_date" before reading your note of caution and have lost my site!!!
Do you have any idea how to fix this?
regards
Sean
This is a jQuery clock. Just
This is a jQuery clock. Just add the js file and
<div id="clock"></div>
to your page.tpl.phphttp://code.google.com/p/epiclock/
Thanks ndwilliams3
... are there any demo's of this clock that I can see?
Clock module
Check this module Clock module for Drupal 6&7
Adding date (or time) to Drupal blocks
The team here were looking to do this and did not want to enable PHP to do this (as that opens up all sorts of security issues).
It is very possible to edit the template .. but if you don't want to do that then you can Javascript quite easily like this:
You can format the date (and time if you need) using some neat Javascript.
This site will show you how: http://www.webdevelopersnotes.com/javascript-date-and-time
Hope that helps.
The ChilledWeb Team.
=-=
I suggest a custom block module rather than shoving something like this in a template file. If using Drupal 7 one could also investigate using https://www.drupal.org/project/clock