How to add date/time to page

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
leet8845
Forum Members
Forum Members
Posts: 40
Joined: Tue Jul 10, 2007 5:53 pm

How to add date/time to page

Post by leet8845 »

Hi,

I'm trying to add the date/time to my CMSMS site.

I have tried some different .js methods, all work fine on my site without CMCMS, but when I try the same method on a my CMSMS site thery don't work.

Can it done with PHP and HTML? Does anyone know a method of acheiving this?

Many Thanks

Lee
alby

Re: How to add date/time to page

Post by alby »

leet8845 wrote: I have tried some different .js methods, all work fine on my site without CMCMS, but when I try the same method on a my CMSMS site thery don't work.
In template you must surround your js with: {literal} ... {/literal}

leet8845 wrote: Can it done with PHP and HTML? Does anyone know a method of acheiving this?
Have you look in plugins section?
There are current_date or (for pages) created_date, recently_updated and last_modified_by

Alby
User avatar
leet8845
Forum Members
Forum Members
Posts: 40
Joined: Tue Jul 10, 2007 5:53 pm

Re: How to add date/time to page

Post by leet8845 »

Thanks Alby,

I have added the {literal} ... {/literal} tags but I think I am doing wrong somehow;

Code: Select all

{literal}<__script__ language="JavaScript" type="text/JavaScript">
function initArray() {
for(i=0;i<initArray.arguments.length; i++)
this[i] = initArray.arguments[i];
}
var isnMonths=new initArray("JANUARY","FEBRUARY","MARCH",
"APRIL","MAY","JUNE",
"JULY","AUGUST","SEPTEMBER",
"OCTOBER","NOVEMBER","DECEMBER");
var isnDays= new initArray("Sun","Mon","Tue","Wed",
"Thu","Fri","Sat","Sun");
today=new Date();
hrs=today.getHours();
min=today.getMinutes();
sec=today.getSeconds();
clckh=""+((hrs>12)?hrs-12:hrs); 
clckm=((min<10)?"0":"")+min;
clck=(hrs>=12)?"PM":"AM";

var stnr="";
var ns="0123456789";
var a="";

function getFullYear(d) { // d is a date object
yr = d.getYear();
if (yr < 1000)
yr+=1900;
return yr;
}
</__script>
<__script__>document.write(" "+isnDays[today.getDay()]+", "+isnMonths[today.getMonth()]+" "+today.getDate()+", "+getFullYear(today)+"");</__script>

<__script__>document.write(" "+clckh+":"+clckm+" "+clck+" ");</__script>{/literal}
Any ideas?

Many Thanks

Lee
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to add date/time to page

Post by calguy1000 »

smarty has variables built in for the date and time
as well as customcontent
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: How to add date/time to page

Post by Nullig »

I have a UDT that I use called servertime that I call in my footer. It puts a "realtime" clock wherever you place it.

The UDT code:

Code: Select all

list($sy,$sm,$sd,$sh,$si,$ss) = explode(",", date("Y,n,j,G,i,s"));
$isi = intval($si);
$iss = intval($ss);
$host = $_SERVER['HTTP_HOST'];
echo "
<__script__ type=\"text/javascript\">
<!--
function clock() {
    document.write('<span id=\"clock\"></span>');
    var server = new Date($sy, $sm, $sd, $sh, $isi, $iss).getTime();
    var client = new Date().getTime();
    tick(client-server);
}
function tick(diff) {
    var d = new Date(new Date().getTime()-diff);
    var i = d.getMinutes(); if(i < 10) i='0'+i;
    var s = d.getSeconds(); if(s < 10) s='0'+s;
    var month_names = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(/,/g);
    var clock = document.getElementById(\"clock\");
    if(clock) {
        clock.innerHTML='Server Time: '+
            month_names[d.getMonth()]+' '+d.getDate()+', '+d.getFullYear()+' '+
            d.getHours()+':'+i+':'+s;
        setTimeout('tick(' + diff + ');', 1000);
    }
}

clock();
//-->
</__script>";
Then call it in your template like this:

Code: Select all

{servertime}
Nullig
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to add date/time to page

Post by calguy1000 »

Recomended reading for all users:  http://smarty.php.net/crashcourse.php

the answer to this post is simply {$smarty.now|date_format}

Now if it doesn't display to your liking, then the smarty docs explain exactly how to change the output.

I recommend a 'recommended reading' or a 'have you read this before you post' section be put up somewhere.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “CMSMS Core”