How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Get the Current Year in PHP (and Laravel and JS)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Get the Current Year in PHP (and Laravel and JS)
Web Development

How to Get the Current Year in PHP (and Laravel and JS)

how7o
By how7o
Last updated: May 22, 2026
4 Min Read
Get the current year in PHP, Laravel and JavaScript
SHARE

To get the current year in PHP, use date('Y'). It returns the four-digit year as a string. Laravel users can use now()->year (a Carbon shortcut) or the same date('Y'). For a JavaScript-only equivalent, new Date().getFullYear().

Contents
  • Plain PHP
  • Laravel / Blade
  • JavaScript (static sites, SPAs)
  • Auto-updating copyright range
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on PHP 8.3 and Laravel 11. Originally published 2022-11-23, rewritten and updated 2026-05-17.

Plain PHP

<?php echo date('Y'); ?>
<!-- 2026 -->

The 'Y' format token is the four-digit year. Other useful tokens: 'y' for two-digit (26), 'o' for the ISO-8601 week-numbering year (matters only across the year boundary in week 1/52).

Current year — PHP date('Y'), Laravel now()->year, JavaScript getFullYear” class=”wp-image-5613″/></figure>



<h2 id=Laravel / Blade
{{ now()->year }}
{{-- 2026 --}}

{{-- Or use date() directly --}}
{{ date('Y') }}

now() returns a Carbon instance — same API as Carbon docs describe, including ->month, ->day, and arithmetic like ->subYears(1)->year.

JavaScript (static sites, SPAs)

<span id="year"></span>
<script>document.getElementById('year').textContent = new Date().getFullYear();</script>

This version is safer than document.write, which can rewrite the page if it runs after the DOM is parsed. Set textContent on a placeholder span — works in every browser without surprises.

Auto-updating copyright range

<!-- PHP -->
© <?php echo 2018 . ' – ' . date('Y'); ?> Your Company

<!-- Laravel -->
© {{ 2018 . ' – ' . now()->year }} Your Company

<!-- JavaScript -->
© <span>2018 – <span id="y"></span></span> Your Company
<script>document.getElementById('y').textContent = new Date().getFullYear();</script>

Hardcode the launch year (2018 in the example) and let the end year roll over by itself.

Frequently asked questions

PHP or JavaScript — which is better for an auto-updating copyright year?

PHP is the right pick when the page is server-rendered (WordPress, Laravel, plain PHP) — the year is in the HTML before it reaches the browser, so search engines and users without JS see it. JavaScript is fine for static sites and SPAs where you don’t have a server to render. The year inside document.write() only renders if JS is enabled, but for a footer copyright the practical difference is invisible to most users.

Which timezone does date('Y') use?

PHP uses the timezone set via date_default_timezone_set() or the date.timezone directive in php.ini. For a footer year the timezone almost never matters (the year is the same across most timezones for 364 days), but for anything time-sensitive set the timezone explicitly: date_default_timezone_set('UTC') at the top of the script.

Why use now()->year in Laravel instead of date('Y')?

Both work. now()->year returns a Carbon instance and gives you a fluent API if you need to do more with the date (now()->subYears(1)->year for last year, etc.). For just the year, date('Y') is shorter and a hair faster. Pick by codebase convention — if the rest of your project uses Carbon, now()->year fits in.

How do I show a year range like “2018 – 2026” that updates automatically?

Hardcode the start year, compute the current year for the end. PHP: <?php echo 2018 . ' – ' . date('Y'); ?>. Laravel: {{ 2018 . ' – ' . now()->year }}. JavaScript: document.write('2018 – ' + new Date().getFullYear()). The start year is the year you launched; the end year ticks forward by itself.

Related guides

  • How to Add a Number of Days to a Date in PHP
  • How to Format a Number with Leading Zeros in PHP
  • How to Display PHP Errors

References

PHP date(): php.net/manual/en/function.date.php. Carbon documentation: carbon.nesbot.com/docs. JavaScript Date.prototype.getFullYear(): developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear.

TAGGED:datesJavaScriptLaravelphp

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Get a favicon URL with JavaScript How to Get a Website’s Favicon URL with JavaScript
Next Article Get a remote file size from URL in PHP with get_headers How to Get a Remote File’s Size from a URL in PHP
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Laravel run project from GitHub — git clone through artisan serve pipeline
Web Development

How to Run a Laravel Project from GitHub

8 Min Read
Laravel request inputs with prefix — filter request()->all() by Str::startsWith
Web Development

How to Retrieve Inputs with a Specific Prefix in Laravel Request

7 Min Read
Select the last child element with jQuery
Web Development

How to Select the Last Child Element in jQuery

4 Min Read
WooCommerce product view counter — meta-based counter with increment and display hooks
Web Development

How to Display a Product View Counter in WooCommerce Without a Plugin

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?