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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:26:59+00:00 2026-06-14T05:26:59+00:00

I have a another question for preg_match . I have a table, where the

  • 0

I have a another question for preg_match.

I have a table, where the date of the comment is written inside the comment itself ( by hand ) and now I need to extract that date and place in a different column.

I found out, that the comments and dates are styled like this:

+-------+----------------------+--------------+
| id    | warning_sent         | warning_date |
+-------+----------------------+--------------+
|  6109 | 2011-06-28           | 0000-00-00   |
|  6123 | 2012 02 14           | 0000-00-00   |
|  6126 | Some text 18.11.10\n | 0000-00-00   | /* This is 2010-11-18 */
| 13750 | 2011-06-28\n         | 0000-00-00   |
|  8108 | 7-01-2010            | 0000-00-00   |
|  9954 | 2012.07.03           | 0000-00-00   |
|  6110 | Some text 21-02-2011 | 0000-00-00   |
+-------+----------------------+--------------+

Now, the only thing, I could think of ( and know how to do ), is looking for the first number, then for the last. And somehow analyzing the string in between, but this comes to a serious problem if the comment text contains a number on its own.

So the question is: How can I find all the dates ( there are only one in each comment ) inside the comments and store them automatically inside the other column in my desired YYYY-MM-DD format?

Edit: This worked, thanx @infinity

$query = "SELECT id, warning_sent FROM data";
$result = qq( $query );

foreach( $result as $values )
{
    preg_match( '/[\d]{4}((-|\s|\.)[\d]{2}){2}|([\d]{1,2}(\.|-)){2}[\d]{2,4}/', $values['warning_sent'], $matches );

    $old_date = $matches[0];
    $new_date = '0000-00-00';

    /* 2011-06-28, 2012 02 14, 18.11.10, 7-01-2010, 2012.07.03, 21-02-2011, 20.10.2010 */
    $formattings = array( 'Y-m-d', 'Y m d', 'd.m.Y', 'd.m.y', 'j-m-Y', 'Y.m.d', 'd-m-Y' );

    for( $k=0; $k<sizeof( $formattings ); $k++ )
    {
        $sub_date = DateTime::createFromFormat( $formattings[$k], $old_date );
        $sub_date = (array)$sub_date;
        $timestamp = strtotime( $sub_date['date'] );
        $check_date = date( $formattings[$k], $timestamp );
        if( $old_date == $check_date ) $new_date = date( 'Y-m-d', $timestamp );
    }

    $warning_sent_date[$values['id']] = $new_date;

}
  • 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-14T05:27:01+00:00Added an answer on June 14, 2026 at 5:27 am

    If you have just these 3 formats that should work

    '/[\d]{4}((-|\s|\.)[\d]{2}){2}|([\d]{1,2}(\.|-)){2}[\d]{2,4}/'
    

    Updates RegEx

    http://regexr.com?32pbf

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

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
I have another question. Quite similar to the other that i already asked (and
I have another question, does any one know how to get the start date
I have another question. XMLhttpRequests haunt me. Everything is now in the database but
ok, i have another question now. I have a bunch of beans loaded succesfully
I have another question that's connected with my class: public class Parent { public
I have (another) question about indexing. I use the following code: CREATE TABLE [dbo].[PnrDetails1](
Aloha everyone, I have another question. I have a SYDI script that retrieves WMI
I have another question for you that I believe I already know WHY it
I have another question: Ajax Forms are working well. Most of them need to

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.