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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:27:06+00:00 2026-06-12T22:27:06+00:00

I’m looking to slightly modify the PHP date() function so that it recognises the

  • 0

I’m looking to slightly modify the PHP date() function so that it recognises the UK 6 digit format of dd/mm/yy or dd-mm-yy. Understandably, it will think that a date which is in this form is instead in international (yy-mm-dd) format.

I still wish to pass it into the date function as this will allow it to recognise other formats, but as I’m based in the UK people are most likely going to put it in the UK format.

Any ideas? I suspect Regex is involved in the solution to this problem…

Update – my solution

Using parts from the answer below, this was how I was able to change it just in the case of dd/mm/yy:

$s_date = str_replace('/', '-', $s_date);

preg_match('^(.*)[-](.*)[-](.*)$^', $s_date, $matches);
if ($matches) {
    if (strlen($matches[3]) == 2) {
        $matches[3] = '20'.$matches[3];
    }
    $s_date = $matches[1].'-'.$matches[2].'-'.$matches[3];
}
  • 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-12T22:27:07+00:00Added an answer on June 12, 2026 at 10:27 pm

    This function will allow you to check for dd-mm-yy and dd/mm/yy.

    By using a str replace – you force the date to always be in the ‘dd-mm-yy’ format. strtotime interprets dates with a “-” as the format you want.

    // Is this a valid date?
        function valid_date($str) 
        {
            $str = str_replace('/', '-', $str);
            if ($arr = strtotime($str))
            {
                $arr = explode("-", date("d-m-Y", strtotime($str)));
                $yyyy = $arr[2];
                $mm = $arr[1];
                $dd = $arr[0];
                if (is_numeric($yyyy) && is_numeric($mm) && is_numeric($dd))
                {
                    return checkdate($mm, $dd, $yyyy);
                }
            }
            return false;
        }
    

    Quote from strtotime:

    if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.