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

  • Home
  • SEARCH
  • 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 7615053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:33:35+00:00 2026-05-31T02:33:35+00:00

I need a regex for validating date and time with the following format: yyyy-mm-ddThh:mm:ss

  • 0

I need a regex for validating date and time with the following format: yyyy-mm-ddThh:mm:ss. T is just a symbol between date and time. Thanks for help

  • 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-05-31T02:33:36+00:00Added an answer on May 31, 2026 at 2:33 am

    Fully-powered solution:

    function validate($str) 
    {
        preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$/', $str, $matches);
    
        if (count($matches) != 7)
            return false;
    
        $valid_year   = range(2000, 2050); // your range
        $valid_month  = range(1, 12);
        $valid_day    = range(1, 31);
        $valid_hour   = range(0, 24);
        $valid_minute = range(0, 59);
        $valid_second = range(0, 59);
    
        list($str, $year, $month, $day, $hour, $minute, $second) = $matches;
    
        foreach(array('year', 'month', 'day', 'hour', 'minute', 'second') as $part)
        {
            if (!in_array($$part, ${'valid_'.$part}))
                return false;
        }
    
        return checkdate($month, $day, $year); // this will reject absurd values like February 30 or April 31
    }
    

    EDIT: I don’t trust strtotime. For example: “The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC.” (quoted from strtotime manual page). What if I want to accept dates out of this range? To me, strtotime is an unknown black-box. Don’t get me wrong: I do use it, eventually! But I wouldn’t for this case.

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

Sidebar

Related Questions

Need help finding or having a RegEx match a MM/YY or MM/YYYY format. My
I need a regex for the following pattern: Total of 5 characters (alpha and
I have a website where I need to parse date/time strings from receipts. These
I'm not a regex guy, so I definitely need help on this. All I
I need regex for validating alphanumeric String with length of 3-5 chars. I tried
For jquery validation i need regex for SSN number format and EIN number format
An open-source cms I'm working on uses the following regex for validating emails: valid_regex=^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$
Possible Duplicate: Validating an IP with regex I need the regular expression for finding
I need to do a validation of an e-mail using annotation + regex. I
Possible Duplicate: A comprehensive regex for phone number validation Greetings, I need to implement

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.