Contact: Web / Voice / Email / Tips
Simple Thoughts Blog - Java and Web Technologies

Simple solutions for complex problems.

 

How To Display Current Year in PHP

March 1st, 2008 by Angsuman Chakraborty

The most common use of this is to display the current year in the copyright message dynamically. Anyone who really knows PHP should be able to do it easily. However not everyone who has to use PHP knows PHP, like, for example, people using snippets in ModX or modifying templates in WordPress. Here is the code snippet for them:
<php echo date('Y') ?>


Tags: How To, Open Source Software, PHP, Programming, Web, Web 2.0, WordPress | | RSS 2.0 | Trackback this Article | Email this Article

You may also like to read

»Fibonacci Series in 1-Line PHP / Java Software
»How To Display / Delete IP Route Cache on Linux
»How To Debug Execution Path in PHP...Equivalent of printStackTrace() in Java
»How To Recover Openfire admin Password
»How To Display Yearly Archives of WordPress Blogs
»GCJ is Dangerously Buggy
»Google Signs 900 Million Dollar Deal With MySpace
»Adding Quotations to Blog
»Wish You All Happy Holidays
»WordPress 3 Column Anaconda Theme Tested on 9 Display Settings
»5 Things I Don't Like About Google Calendar
»Angsuman's Translator Plugin Pro / Gold: Application Program Interface
»Subversion: How To Ignore Files From Status Display
»Favelet to spot nofollow anywhere
»How To Setup Dual Monitors on Linux / Fedora Core

5 Responses to “How To Display Current Year in PHP”

  1. Jay Gilmore (smashingred) Says:

    You might have better luck with the following since your PHP tag is incorrect:

  2. Jay Gilmore (smashingred) Says:

    Um er… Your comment filter killed my code so here it is:

    &lt?php date(’Y'); ?>

  3. Jay Gilmore (smashingred) Says:

    3rd Try is the charm:
    <?php date(’Y'); ?>

  4. Angsuman Chakraborty Says:

    The code is correct. Semicolon is not required before ending PHP tag.

  5. Jay Gilmore (smashingred) Says:

    You are right that the ending semi-colon is not required but the “?” is required to set off the PHP tag it won’t be parsed and will not appear as the browser will parse it as if it were an unknown HTML element.

Looking forward to hear your thoughts.



Please enter the code shown below ( to verify that you are human ) before you click Submit Comment.

No. 1 method to ethically increase your blog traffic and reach.

Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanPřeložit do Čech/CzechOversætte hen til Dansk/DanishKääntää jotta Finnish/FinnishLefordít -hoz Magyar/HungarianÞýða til Íslenska/IcelandicTraducir a Latinoamericano Español/Latin American Spanishtagapagsalin sa Filipino/FilipinoTłumaczyć wobec Polski/PolishA traduce la spre Român/RomanianPrevesti za Srpski/Serbiantolmačiti v slovenski/SlovenianÖversätta till Svensk/SwedishChyfieitha at Cymraeg/Welshtercüme etmek -e doğru Türk/TurkishPrevesti to Hrvatski/CroatianПревеждам към Българин/BulgarianTraduzca al Español/SpanishTraduisez au Français/FrenchTraduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplifiedترجمة الى العربية/ArabicVertaal aan het Nederlands/DutchΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/Norwegian中文翻译/Chinese TraditionalTraduzir a Língua portuguesa brasileira/Brazilian PortugueseReddo ut Latin/Latin

Taragana Network

»Ctrl-S
»Enterprise Blog
»Free Book on Eye Care by Natural Therapy
»Health Care Blog
»Hot Computer Jobs Blog
»Pet Care & Grooming News and Tips
»Phil Law Blog
»Taragana - Software Outsourcing
»The Angsuman Chakraborty Blog
»The Diabetes Cure Blog
»The Eye Treatment Blog
»The Stem Cell Blog
»Weblog Hosting Blog
"A person starts to live when he can live outside himself." - Albert Einstein