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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:20:28+00:00 2026-05-30T16:20:28+00:00

I almost tried for 10 hours to change the date format suits my needs

  • 0

I almost tried for 10 hours to change the date format suits my needs but couldn’t success. I have tried Preg_Replace Strotime functions with following examples.

The current date format is : 02-25-2006
Want to convert to: 2006-02-25

Here are the list of examples I have tried:

publishdate = "02-20-2012";  
echo preg_replace("/\d{2}-\d{2}-\d{4}/","$3/$1/$2",$publishdate); 

$dateString= '2006-09-14';
echo date("m/d/Y", strtotime($dateString));



$dateString1= '02-20-2012';
echo date("Y/m/d", strtotime($dateString1));



$date1 = '05-25-2010';
echo date('Y-m-d', strtotime($date1));

$dateString2= '02-20-2012';
echo preg_replace("/(\d{2})-(\d{4})-(\d{2})/","$2/$3/$1",$dateString2);  
  • 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-30T16:20:29+00:00Added an answer on May 30, 2026 at 4:20 pm

    ad regexp:

    you must mark capture groups in your regexp if you want to use partial matches in your substituting expression! you do so by enclosing parts of your regexp pattern in parentheses. so your regexp should be /(\d{2})-(\d{2})-(\d{4})/. more info in the regexp docs, notably the section on subpatterns.

    ad strtotime:

    if you choose - as a date part separator, days must come first. thus 02/20/2012 will work as well as 20-02-2012 while 02-20-2012 won’t. for more details on supported date/time formats consult the docs.

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

Sidebar

Related Questions

I have almost tried everything but for some reason it is not working <StackPanel
I have tried almost everything and I can't seem to get my lists to
I have asp.net website name http://www.go4sharepoint.com I have tried almost all ways to improve
Okay, I have looked everywhere and tried almost every suggestion that I could find
I've tried almost everything imaginable (apart from the right thing of course), but still
I've seen this question being asked 1000 times, but I'd tried almost all methods
I have tried almost all of the jQuery Modal plugins I can find on
I am using WinForms, i have tried TreeView and it almost have similar structure
I've tried almost everything. In my nginx.conf I have rails_env set to production in
( Almost exact duplicate of Keeping original format POST passing through AWK submitted by

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.