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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:07:40+00:00 2026-06-13T23:07:40+00:00

Whats the problem in that code that output the wrong date? $date = 1990-05-07;

  • 0

Whats the problem in that code that output the wrong date?

$date = "1990-05-07"; // Y-m-d
$date1 = date("d/m/Y", strtotime($date)); // Here is fine.
$date2 = date("Y-m-d", strtotime($date1)); // Here is wrong.

echo $date2; // output: 1990-07-05

The code above is a simple demonstration, the exactly code is: (Yii Framework)

Model.php

public function afterFind()
{
    if ($this->birthday)
    {
        $this->birthday = date("d/m/Y", strtotime($this->birthday));
    }
}

public function beforeSave()
{
    if ($this->birthday)
    {
        $this->birthday = date("Y-m-d", strtotime($this->birthday));
    }
}
  • 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-13T23:07:41+00:00Added an answer on June 13, 2026 at 11:07 pm

    Solution Using ‘Vikas Umrao’ TIP:

    public function afterFind()
    {
        if ($this->birthday)
        {
            $birthday = explode("-", $this->birthday);
            $mktime = mktime(0,0,0,$birthday[1],$birthday[2],$birthday[0]);
            $this->birthday = date("d/m/Y",$mktime);
        }
    }
    
    public function beforeSave()
    {
        if ($this->birthday)
        {
            $birthday = explode("/", $this->birthday);
            $mktime = mktime(0,0,0,$birthday[1],$birthday[0],$birthday[2]);
            $this->birthday = date("Y-m-d",$mktime);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So what my code looks like.. Now the problem is that Everything is fine
I faced with the problem that the kernel writes data in wrong place or
I'm working on some code that uses error_log() for debugging. The problem is that
this problem is killing me, here is my code import java.text.ParseException; import java.text.SimpleDateFormat; import
Greetings, what is the problem that when I try to set credentials for my
What do you do when you encounter a programming problem that is really hard
I understand the problem that OSGI solved thanks to this question.... What does OSGi
I have a problem that is kind of difficult to explain. What I would
I am experiencing what I consider to be a weird problem that I am
So we have this problem that we are trying to figure out. Heres what

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.