SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Warning Newbie Calling for Code.....

    Does anybody know of code to display the date on my website in the format Friday, 16 October 2009 using Arial font size 2 or 3 colour CC5617 ??

  2. #2
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Well, that's quite a loaded question... did you want the date dynamically entered into your website or are you adding the date to posts manually? If you are adding it manually then no problem, if you want to edit it dynamically you will either need to use JavaScript (if you want to display the current date) or a server-side script (if you want the date of the post). As for the style, what font measurement are you intending on using? they don't come in 2 or 3, it's usually a measurement unit like px, em, % or something similar (the font, size and color would need to use CSS, not HTML). And as for the whole thing itself, where are you intending on adding it? It depends where it's going and what the rest of your code is as to what html element you need to use.

    Really we can't help you unless your MUCH more explicit with your question.

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Alex, what I want to do is to have the day date display on the webpage and to update dynamically. The only example I can think of is the bbc website. it has a clock in the top right corner and below it has the date, does that help? sorry to be so ignorant...

    Yes, I want to display the current date so JavaScript is what is needed I guess. For the font measurement I am unsure of the px but it is roughly size 10 font if that makes sense? I would just place it somewhere in the body.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,117
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Hi klorigan,

    You can easily use PHP to place the date on every page, like this:

    PHP Code:
    <?php
    $timestamp 
    time();
    echo 
    date("l, F jS Y"$timestamp);
    ?>
    That will echo the date for your own server (i.e. if the server is in the US, it will show local US date--unless you've specified otherwise). There are ways to make the time vary depending on the site visitor's location. For example, here is how to set a time for both the server location and a visitor say in Melbourne, Australia (where I am):

    PHP Code:
    <?php
    $timestamp 
    time();
    echo 
    date("l, F jS Y"$timestamp) . '<br />';  // server time
    date_default_timezone_set('Australia/Melbourne');
    echo 
    date("l, F jS Y"$timestamp) . '<br />'// Melbourne time
    ?>
    As for the font size issue, the font size = 3 is old presentational HTML markup, like this:

    Code:
    <p><font size="3">Friday, 16 October 2009</font></p>
    You should avoid this like the plague. Better to do this in your HTML:

    Code:
    <p class="date"><?php $timestamp = time(); echo date("l, F jS Y", $timestamp); ?></p>
    and then this in your CSS file:

    Code:
    .date {
      font-size: 10px; /* adjust to suit */
      color: #CC5617;
      font-family: arial, verdana, helvetica, sans-serif;
    }
    Hope that's all clear!
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  5. #5
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by klorigan View Post
    Yes, I want to display the current date so JavaScript is what is needed I guess. For the font measurement I am unsure of the px but it is roughly size 10 font if that makes sense? I would just place it somewhere in the body.
    Sorry about the lateness of my reply, the below website has plenty of examples of JavaScript clocks which will update as you want it too (or at least what you have been hinting at). As for the font size all font's are declared in a specific measurement (like px), If you mean font size 10 as in what a word processor would use (they tend to be undefined) it would be in pt (points) rather than anything else, though i would highly advise you don't use PT as it's not intended for anything other than print media. I would start by using font-size: 14px; in your CSS and then adjust it to meet your needs.

    http://www.dynamicdrive.com/dynamicindex6/

  6. #6
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Alex, I appreciate this very much. However, when I said newbie what I meant was newborn foal trying to gallop before I can even stand up...!
    I can place code to the body or the head and don't understand when people say put in your css. I do know what css is just haven't used it.
    Again, sorry for being so useless....!

  7. #7
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Ralph, if you see my reply to Alex below you will understand that I need step by step.....arrgghh.
    I understand the code as you present it but I don't have css I can place code in body or head???

  8. #8
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,117
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    OK klorigan, to be clearer, just do these three things (if you want to utilize my PHP example):

    1. Make sure that your page has a .php extension. (For example, instead of index.html, call it index.php.)

    2. Place this in your HTML (that is, in the <body> section) wherever you want the time to appear:

    Code:
    <p class="date"><?php $timestamp = time(); echo date("l, F jS Y", $timestamp); ?></p>
    3. Place this code in the <head> section of any page on which the time is to appear:

    Code:
    <style type="text/css" media="all">
    .date {
      font-size: 10px; /* adjust to suit */
      color: #CC5617;
      font-family: arial, verdana, helvetica, sans-serif;
    }
    </style>
    If you want the time to appear on multiple pages, that last step is quite inefficient, as you would have to revisit each page if you ever wanted to change your styles.

    A better approach is to create an external CSS file. For example, create a new page called time.css and, for argument's sake, place it in your root folder (where your home page is).

    In that file stick this code:

    Code:
    .date {
      font-size: 10px; /* adjust to suit */
      color: #CC5617;
      font-family: arial, verdana, helvetica, sans-serif;
    }
    Then in the <head> section of each page, place this code:

    Code:
    <link type="text/css" media="all" rel="stylesheet" href="/time.css">
    This is better because, if you later want to change your styles, you can do so in one loaction, and all pages will be updated at once.

    I hope these instructions are simple enough to follow!
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for this instructions this will help me a lot!
    Easy Website Builder | Building Website Fast and Easy
    Hevla Coffee Co. | Low Acid Coffee and Accessories.

  10. #10
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Just a note: Using that code means you will get a time stamp upon the pages loading, however this isn't dynamic and does not alter by the second (as I thought you wanted) for that your would need to employ the use of JavaScript following the instructions for the examples, or perhaps Ralph's solution was what you wanted


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •