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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:42:03+00:00 2026-05-26T20:42:03+00:00

I am rebuilding a web application from an old one with many inconsistencies. I

  • 0

I am rebuilding a web application from an old one with many inconsistencies. I have to migrate all the data over from the old database to our new structure.

In the old database, dates were stored in the MySQL DB as VARCHAR. We are based in the UK, so dates were written in the format DD/MM/YYYY. I need to convert these dates to MySQL’s native DATE() format.

Problem is this – PHP defaults to assuming the dates are in ‘American’ format (MM/DD/YYYY) because they were originally split with / rather than - – and - forces PHP to assume they are ‘European’ format.

I am doing this so far to convert them:

$start_date = date('Y-m-d', strtotime($query->row('startdate')));

Where $query->row('startdate') is the column in the old database which was storing the dates. Problem is, I need to first switch all the 21/03/1994s to 21-03-1994.

How can I do this?

  • 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-26T20:42:03+00:00Added an answer on May 26, 2026 at 8:42 pm
    $start_date = date('Y-m-d', strtotime(str_replace('/', '-', $query->row('startdate'))));
    

    Or better yet – just change the data in the database:

    UPDATE `table` SET `startdate` = REPLACE(`startdate`, '/', '-');
    

    … and then convert the field to type DATE.

    —- EDIT —-

    Actually, Col. Shrapnel has a point … I’d overlooked the fact that the date needs reversing as well so it’s YYYY-MM-DD; assuming the original date is in the format DD/MM/YYYY a better query might be something like:

    UPDATE `table` SET `date` = CONCAT(SUBSTRING(`date`, 7), '-', SUBSTRING(`date`, 4, 2), '-', SUBSTRING(`date`, 1, 2))
    

    Which will reverse the component parts into a string that can be converted to a DATE … it won’t quite work if the original date string doesn’t use leading zeroes 1/6/2011 for instance… would need to do something a little cleverer in that case.

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

Sidebar

Related Questions

I have a database the I am rebuilding the table structure was crap so
I'm converting a web forms application to mvc3 , for the current database it
I have a query from a web site that takes 15-30 seconds while the
Consider following assumptions: I have Java 5.0 Web Application for which I'm considering to
I have a spring web application which has several modules. Each module has its
I'm working with a legacy database while re-building the web application. I want to
We're building a commandline application that needs some data from the IIS server using
So, I am currently rebuilding my web platform from a single-machine to a cluster
I use VS 2010 Ultimate. I created an 'asp.net web application' from scratch, added
I have an ASP.Net 4.0 web forms application that is ignoring any changes I

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.