Veshyr
Veshyr

Reputation: 1

PHP - DatePicker/String conversion to SQL Date

I have a DatePicker that gives me a value like this "10-Nov-2016". I want to convert this date into a SQL Date such as "2016/10/22".

What would be the best way to do this?

Any help appreciated, thank you.

Upvotes: 0

Views: 311

Answers (2)

LF-DevJourney
LF-DevJourney

Reputation: 28524

use date() and strtotime() function

echo date('Y/m/d', strtotime('15-Feb-2009'));

demo

Upvotes: 0

qkr
qkr

Reputation: 451

Use DateTime::createFromFormat or procedural version date_create_from_format.

$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y/m/d');

Upvotes: 1

Related Questions