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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:10:00+00:00 2026-05-17T19:10:00+00:00

I have problem with date function in php. If I supply string in format

  • 0

I have problem with date function in php. If I supply string in format “d.m.y” for example “01.01.01” it gets rendered as todays date which means that php gets confused.

I found:

Note:

The “Day, month and two digit year, with dots or tabs” format (dd [.\t] mm “.” yy)
only works for the year values 61 (inclusive) to 99
(inclusive) – outside those years the time format “HH [.:] MM [.:] SS” has
precedence.

on: php.net site

How to override this behavior?

I know of date_create_from_format function which would work fine if I knew input will always be in format “d.m.y”, but it won’t.

UPDATE 1:

Code

$date = new DateTime('01.01.01');
echo $date->format('Y-m-d');

outputs 2010-10-19 and I wanted 2001-01-01.

  • 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-17T19:10:00+00:00Added an answer on May 17, 2026 at 7:10 pm
    function getDateFromString( $str )
    {
        $date = DateTime::createFromFormat( 'd.m.y', $str );
        if ( $date !== false )
            return $date->getTimestamp();
    
        // you can try other common formats here
        // ...
    
        // otherwise just parse whatever there is
        return strtotime( $str );
    }
    
    echo date( 'd.m.Y H:i', getDateFromString( '01.01.01' ) ); // 01.01.2001 20:14
    

    Edit

    To adjust it a bit more to get your exact output:

    function getDateTimeFromString( $str )
    {
        $date = DateTime::createFromFormat( 'd.m.y', $str );
        if ( $date !== false )
            return $date;
    
        // you can try other common formats here
        // ...
    
        // otherwise just parse whatever there is
        return new DateTime( $str );
    }
    
    $date = getDateTimeFromString( '01.01.01' );
    echo $date->format( 'Y-m-d' ); // 2001-01-01
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bizzare problem with php date function. code: $numDays = 8; $date
I have a weird date rounding problem that hopefully someone can solve. My client
I have problem with synchronizing results of function I get with AJAX with that
I have some PHP code that inserts a date into a table: INSERT INTO
With reference to Problem with date day/month reversing on save I have further noted
I have problem in some JavaScript that I am writing where the Switch statement
I have a problem using the Java search function in Eclipse on a particular
I recently came across a big problem, as I have a system that's paying
<?php function date($x) { $contents = $_FILES['userfile']['tmp_name']; $contents = file($contents); $date = $contents[$x][6].$contents[$x][7] .-.$contents[$x][8].$contents[$x][9]
I have a problem with the jquery $.get function. I'm trying to get data

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.