Global Friends Online

Please login or register.

Login with username, password and session length
Advanced search  

News:

February 02, 2009: Our Welcome And Staff Information

Pages: [1]   Go Down

Author Topic: Display the current year on your site.  (Read 296 times)

0 Members and 1 Guest are viewing this topic.

~penguin~

  • Global Bippy
  • Global Moderator
  • Global Family
  • *****
  • Offline Offline
  • Posts: 3422
  • Evil Bippy
    • WWW
Display the current year on your site.
« on: December 17, 2008, 03:29:27 PM »
Something that can be very useful this time of the year. Keep the year of your site always up to date:

Adding this code to a .php-page:
Code: [Select]
<?php
    
echo "&copy; ";
    echo 
date("Y");
    echo 
" globalfriendsonline.com";
?>
Will give as result: © 2008 globalfriendsonline.com

That's a pretty useful start, but how would it look if you wanted to print the date as it does on the top of this page? :hmm2:

Use the following code for that:
Code: [Select]
<?php 
echo 
date("F j, Y, h:i:s A");
?>

F j, Y, h:i:s A? This may seem difficult at first sight, but: F=month, j=day and so on,for a full list of all characters to use, go to: http://php.net/date

Just to be clear for everyone, in php-pages you can just write html codes. Please note, your host needs to support PHP (4 or 5) for this to work.

randomforumblokey

  • Global Pal
  • **
  • Offline Offline
  • Posts: 73
Re: Display the current year on your site.
« Reply #1 on: December 17, 2008, 05:58:49 PM »
Or MySQL Datetime

Quote
<?php $mysqltime = date ("Y-m-d H:i:s", $phptime); ?>

Or use POSIX strftime.


Or if you prefer not to use a function, in Perl:

Quote
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
 
my $datetime = sprintf "%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec;
Logged




Quote
...its author can be excused of dishonesty only on the grounds that before deceiving others he has taken great pains to deceive himself - Sir Peter Brian Medawar (oddly, not speaking of internet forums)

adam7one

  • Just an ordinary bloke
  • Global Relative
  • ****
  • Offline Offline
  • Posts: 361
  • gettingpaidonline.com
    • WWW
Re: Display the current year on your site.
« Reply #2 on: December 18, 2008, 05:20:48 AM »
I use a javascript on some of sites to give date and time
Code: [Select]
<script language="JavaScript">
  <!--
    var now = new Date();
    var days = new Array(
      'Sunday','Monday','Tuesday',
      'Wednesday','Thursday','Friday','Saturday');
    var months = new Array(
      'January','February','March','April','May',
      'June','July','August','September','October',
      'November','December');
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
    function fourdigits(number) {
      return (number < 1000) ? number + 1900 : number;}
    today =  days[now.getDay()] + ", " +
       months[now.getMonth()] + " " +
       date + ", " +
       (fourdigits(now.getYear()));
     document.write(today);
  //-->
</script>

~penguin~

  • Global Bippy
  • Global Moderator
  • Global Family
  • *****
  • Offline Offline
  • Posts: 3422
  • Evil Bippy
    • WWW
Re: Display the current year on your site.
« Reply #3 on: December 18, 2008, 08:34:30 AM »
Thanks both for that valuable information! :clap:

astrangemix

  • Global member
  • Global Relative
  • *
  • Offline Offline
  • Posts: 260
    • WWW
Re: Display the current year on your site.
« Reply #4 on: December 18, 2008, 09:15:00 AM »

I took the easy road and went to timeanddate.com and had them generate a line of code that would show the date/time on ME  :blush:   :P
Logged

Some days it just isn't worth chewing through the straps.

Pages: [1]   Go Up
« previous next »
 



Cashin Clicks | That Animal Site | Used Paperback Books | Tri-Peak Solitaire | Need extra money for personal spending?