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
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

GitHub Actions workflow deploying Laravel to a VPS, zero-downtime symlink swap
Web Development

How to Deploy a Laravel App to a VPS with GitHub Actions (Zero-Downtime, No Forge)

11 Min Read
Laravel foreign key constraint linking posts.user_id to users.id in a schema diagram
Web Development

How to Add Foreign Keys in Laravel Migration

6 Min Read
Check if an element is hidden or visible with jQuery
Web Development

How to Check if an Element Is Hidden or Visible with jQuery

4 Min Read
Laravel Blade Time Format (HH:MM)
Web Development

How to Show Only Hours and Minutes in Laravel Blade (HH:MM)

3 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?