-1

I know there is a MySQL function that converts string to date, but it requires the string format.

Is there a way to do it without knowing the format?

Or is there a way to get the format using PHP so that I can use it in MySQL?

Community
  • 1
  • 1
Jake
  • 11,273
  • 21
  • 90
  • 147
  • 2
    Just curious, what date will `12/11/10` or `12/11/2010` represent in your hypothetical function? – Anshul Goyal Nov 14 '13 at 04:31
  • Any reasons for downvoting? – Jake Nov 14 '13 at 04:33
  • As ansh01 noted, depending on the date given, you could have several different valid dates. Why do you need to do this? Do you really not know what format the date is provided in? – Josh Mein Nov 14 '13 at 04:35
  • @ansh0l does not matter. This can be accepted as implementation specific. – Jake Nov 14 '13 at 04:35
  • @JoshMein date('Y-m-d', strtotime($string)) is an acceptable conversion without the API user knowing or actually finding out the format. – Jake Nov 14 '13 at 04:37
  • @Jake How are you deciding `date('Y-m-d', strtotime($string)) ` is acceptable? Why can't `date('m-d-Y', strtotime($string)) ` be the acceptable format? – Anshul Goyal Nov 14 '13 at 04:43
  • @ansh0l I'd assume you guys are having a bad day, and I'll avoid getting into a debate that's not related to the question. Take care. – Jake Nov 14 '13 at 04:49

2 Answers2

2
Do you mean this ?
SELECT unix_timestamp('2013-11-14'), 
unix_timestamp('2013/11/14'), 
unix_timestamp('13/11/14'), 
unix_timestamp('13-11-14'),
from_unixtime(unix_timestamp('13-11-14'))

This will output 
1384358400 1384358400 1384358400 1384358400 "2013-11-14 00:00:00".
Zjmainstay
  • 123
  • 6
1

use strtotime() function of php, hope it may help go through below link.

http://php.net/manual/en/function.strtotime.php

Abhishek
  • 1,543
  • 3
  • 13
  • 29