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 9003943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:47:13+00:00 2026-06-16T00:47:13+00:00

I have a date validator code segment, its supposed to validate any future date.

  • 0

I have a date validator code segment, its supposed to validate any future date. For debugging purposes I want it to expire by Tomorrow, or in about 3 hours. As of writing this Tomorrow is Dec 18. Its 10:40PM GMT-5 Dec 17 It flags it as the past. dates get entered with 3 post variables: day, month, year and are concatenated, “01:01:59” appended, and inserted as a timestamp into a table, where its preiodically checked by a script to see if the item has expired. The code below will not validate any date closer than 2 days away. I can’t figure out why.

code:

if(check_post('day')&&check_post('month')&&check_post('year'))
{
    //die("day: ".$_POST['day']." month: ".$_POST['month']." year: ".$_POST['year']);
    if(!check_post('day',"Select Day")&&!check_post('month',"Select Month")&&!check_post('year',"Select Year"))
    {
        $days = array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
        $today = explode("-",date("d-m-Y"));
        if(checkdate($_POST['month'],$_POST['day'],$_POST['year']))
        {
            $c_y = ($_POST['year']==$today[2]);
            $c_m = ($_POST['month']==$today[1]);
            $p_d = ($today[0]>$_POST['day']);
            $p_m = ($today[1]>$_POST['month']);
            if(!($c_y&&(($c_m&&$p_d)||$p_m)))
            {
                $_POST['date']=strval($_POST['year'])."-".(($_POST['month']>9)?strval($_POST['month']):"0".strval($_POST['month']))."-".(($_POST['day']>9)?strval($_POST['day']):"0".strval($_POST['day']));
                $_POST['date'] .= " 01:01:59";
                //$_POST['date'] = mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
                //die($_POST['date']);
            }
            else
            {
                add_error("Date must be current");
            }
        }
        else
        {
            add_error("Invalid expiration date");
        }
    }
    else 
    {
        add_error("Pick an expiration date");
    }
}
else
{
    add_error("Date not set");
}

There isn’t some function that does this for me right?

  • 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-16T00:47:14+00:00Added an answer on June 16, 2026 at 12:47 am

    A simple string comparison will do:

    $today = date("Y-m-d");
    $date = $_POST['year'] . '-' . 
        str_pad($_POST['month'], '0', 2, STR_PAD_LEFT} . '-' .
        str_pad($_POST['day'], '0', 2, STR_PAD_LEFT);
    
    if ($date > $today) {
        // future date
    } else {
        // something else
    }
    

    Or:

    if (strtotime("{$_POST['year']}-{$_POST['month']}-{$_POST['day']}") > time()) {
        // future date
    }
    

    This is not entirely the same because time() also has both a date AND time component, but it should work just fine as well.

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

Sidebar

Related Questions

I have a field for date e.g. dd/mm/yyyy . I have validate code that
I have some problems with custom validator constraints. I want to validate a field
I have a custom data annotation validator to validate the date of birth to
I have the following regex date validator but it is allowing the following date:
How do you validate a date in MySQL ? In SQL Server, we have
I'm trying to validate mm-dd-(2012~2099) date format. I have the following regular expression. ^(0[1-9]|1[0-2])-(0[1-9]|[10-31])-(20[12-99])$
I have date 2012-04-02 10:01:00 am I want to show this date in with
I have date formatted in this way: 2010-02-04T00:00:00 I use this code to parse
I have date in sting object in following format. dd/mm/yyyy I want to change
I have a date in String format, mm/dd/yyyy I want to convert this to

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.