Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:10:29+00:00 2026-06-11T22:10:29+00:00

I want to check whether the current year is greater than a date string(D-M-Y)

  • 0

I want to check whether the current year is greater than a date string(D-M-Y) here is my code

$OldDate = "09-30-2011";
$OldYear = strtok($OldDate, '-');
$NewYear = date("Y");

if ($OldYear < $NewYear) {
    echo "Year is less than current year"   
} else {
    echo "Year is greater than current year";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:10:30+00:00Added an answer on June 11, 2026 at 10:10 pm

    You can use strtotime():

    $OldDate = "2011-09-30";
    
    $oldDateUnix = strtotime($OldDate);
    if(date("Y", $oldDateUnix) < date("Y")) {
        echo "Year is less than current year";
    } else {
        echo "Year is greater than current year";
    }
    

    UPDATE

    Because you’re using an unconventional datestamp, you have to use different methods, eg:

    $OldDate = "09-30-2011";
    list($month, $day, $year) = explode("-", $OldDate);
    $oldDateUnix = strtotime($year . "-" . $month . "-" . $day);
    if(date("Y", $oldDateUnix) < date("Y")) {
        echo "Year is less than current year";
    } else {
        echo "Year is greater than current year";
    }
    

    NOTE: If you want to always be sure that your date gets correctly understood by strtotime, use YYYY-MM-DD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check whether a string is a file name (name DOT ext)
I want to check whether a date is between start date and end date.
I want to check whether the current time is in between 10AM and 10PM.
Right now, if I want to check whether the current page is accessed through
I want to check whether the current time is between 10.30AM and 11.30AM with
I want to check whether any Zip file is present on a specified path.
I want to check whether a given file exists in android sd card. I
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table
I want to check whether or not a cookie is set with every page
I want to check whether the endpoint is defined in the configuration before I'll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.