Skip to content
Fix Code Error

How do I use PHP to get the current year?

March 13, 2021 by Code Error
Posted By: Anonymous

I want to put a copyright notice in the footer of a web site, but I think it’s incredibly tacky for the year to be outdated.

How would I make the year update automatically with PHP 4 or PHP 5?

Solution

You can use either date or strftime. In this case I’d say it doesn’t matter as a year is a year, no matter what (unless there’s a locale that formats the year differently?)

For example:

<?php echo date("Y"); ?>

On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the php manual on date:

To format dates in other languages,
you should use the setlocale() and
strftime() functions instead of
date().

From this point of view, I think it would be best to use strftime as much as possible, if you even have a remote possibility of having to localize your application. If that’s not an issue, pick the one you like best.

Answered By: Erik van Brakel

Related Articles

  • Polymer- App Route with Sub Paging
  • How to solve Internal Server Error in Next.Js?
  • Set Locale programmatically
  • Image on footer in Bootstrap
  • How to change language of app when user selects language?
  • Do copyright dates need to be updated?
  • Vuetify issue with v-menu
  • Current time formatting with Javascript
  • When tab is selected, show next tab.. if last tab…
  • How to echo with different colors in the Windows…
  • Vue i18n - adding locale to the URL using routerview
  • Changing Locale within the app itself
  • Footer Position in Shiny
  • How to align footer (div) to the bottom of the page?
  • Convert Java Date to UTC String
  • vue-i18n $t with values attribute is not translating
  • How to print a date in a regular format?
  • Calculating Time Difference
  • Java string to date conversion
  • Error creating bean with name
  • How to create a sticky footer that plays well with…
  • How do I set the default locale in the JVM?
  • Conditionally wrapping insertion points in Polymer
  • Next.js router locale issue
  • Vue-router translating url
  • Use of String.Format in JavaScript?
  • converting epoch time with milliseconds to datetime
  • How to internationalize a React Native Expo App?
  • Change parent state from child (where both are…
  • Using CTE in Oracle SQL (ORA-00923: FROM keyword not…
  • XMLHttpRequest cannot load ✘✘✘ No…
  • Echo a blank (empty) line to the console from a…
  • datetime to string with series in python pandas
  • pip install - locale.Error: unsupported locale setting
  • Using timedelta and strftime on column converted to datetime
  • How does PHP 'foreach' actually work?
  • Convert python datetime to epoch with strftime
  • What are the valid Style Format Strings for a…
  • One div is overlapping another when using polymer
  • Removing double quotes from variables in batch file…
  • Quickly getting to YYYY-mm-dd HH:MM:SS in Perl
  • Ukkonen's suffix tree algorithm in plain English
  • What's the best way of scraping data from a website?
  • Multipart File Upload Using Spring Rest Template +…
  • Get current date, given a timezone in PHP?
  • Vue.js - trying to write a computed to return a…
  • Ember.js - where should interface state be stored?
  • Next.js 10 + sub-routing, how to access locale in…
  • vue-i18n doesn't update locale after integrating vuex
  • Bootstrap 4 card-deck with number of columns based…
  • Footer not staying at the bottom when scrolling
  • Change the location of the ~ directory in a Windows…
  • CSS "Sticky Footer" with additonal wrapper div
  • "Thinking in AngularJS" if I have a jQuery background?
  • How to add sticky footer to Polymer Starter Kit with…
  • Converting string into datetime
  • PHP for loop Show the entries in ascending order by quantity
  • How do i update a javascript variable as its value changes?
  • How to get Locale from its String representation in Java?
  • Bootstrap - center child when parent isn't centered…
  • Unable to override blue color of link by inheriting…
  • Laravel return home with locale parameter
  • Reloading the backbone view and i18n translation…
  • data.table vs dplyr: can one do something well the…
  • Best practice multi language website
  • ASP.NET Web Site or ASP.NET Web Application?
  • Unknown string format. transforming a datetime python
  • Vue js, footer not displaying
  • material Design with Angular Dart and Polymer dart.…
  • Using if(isset($_POST['submit'])) to not display…
  • Polymer custom element attribute/property binding…
  • Getting the difference between two Dates…
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Fill remaining vertical space with CSS using display:flex
  • Should MySQL have its timezone set to UTC?
  • i have this error what is the solve for it
  • JSP tricks to make templating easier?
  • Smart way to truncate long strings
  • Bootstrap 3 Flush footer to bottom. not fixed
  • Pandas - Calculate with datetime column with month…
  • Remove first n "words" from string variable in Bash
  • Angular.js and HTML5 date input value -- how to get…
  • Swift - How to convert String to Double
  • Reference — What does this symbol mean in PHP?
  • "Notice: Undefined variable", "Notice: Undefined…
  • How to fetch API at component level and prerender it…
  • I want to create a SQLite database like in the…
  • How to get $HOME directory of different user in bash script?
  • dart-polymer update polymer dom elements
  • How can I change color of date on the datepicker vuetify?
  • ImproperlyConfigured: You must either define the…
  • How do I change the language of moment.js?
  • Get current time in hours and minutes
  • Using %f with strftime() in Python to get microseconds
  • python date of the previous month
  • Selenium. Unable to locate element from the html website
  • Codeigniter 4 hasChanged() - I was expecting no…
  • HTML5 best practices; section/header/aside/article elements
  • Change app language programmatically in Android
  • How are zlib, gzip and zip related? What do they…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Ignoring directories in Git repositories on Windows

Next Post:

Passing parameters to a Bash function

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error