How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Get the Current Year in PHP (and Laravel and JS)
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • 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.

You Might Also Like

Fix missing PHP Authorization header on Apache and cPanel
Server Management

How to Fix Missing Authorization Header in PHP Requests

5 Min Read
Laravel delete file from public folder — File::delete with public_path
Web Development

How to Delete Files from the Public Folder in Laravel

7 Min Read
Laravel 403 forbidden on shared hosting — root htaccess rewrite into public folder
Web Development

Fix “403 Forbidden” on Laravel Shared Hosting

8 Min Read
JavaScript format number with decimals — toFixed, Math.floor, and Intl.NumberFormat
Web Development

How to Format a Number with Decimals in JavaScript

5 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • 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?