-6

I am trying to convert a date in string format to date format, here is the example

1. 15Oct15 to 2015-10-15
2. 151015  to 2015-10-15
3. 15102015 to 2015-10-15

Please help me to find a solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
Arif K
  • 9
  • 2
  • 2
    Have you googled convert string to php date? Cause I just have and the first hit was a question on here that perfectly outlines how to do exactly what you want to do. – Lee Sep 16 '15 at 10:07
  • You could use a regex to determine which format you have, and then split it into pieces. Would you try writing some code? You may be able to do it on your own. – halfer Sep 16 '15 at 10:12
  • $d1='15Oct15'; echo $d=date('Y-m-d',strtotime($d1)); => 2015-10-15 You have to change the format of $d2 & $d3 atleast like this. Then, only you can expect the result. $d2='15-10-15'; echo $d=date('Y-m-d',strtotime($d2)); => 2015-10-15 $d3='15-10-2015'; echo $d=date('Y-m-d',strtotime($d3)); => 2015-10-15 ?> – Nana Partykar Sep 16 '15 at 10:47

1 Answers1

0

You can convert 1. 15Oct15 to 2015-10-15 using date('Y-m-d', strtotime("15Oct15"))

Not sure of other 2