Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date in format MM/DD/YYYY to MySQL date [duplicate]

Tags:

php

mysql

I have a PHP function that gets passed a date in the format MM/DD/YYYY I need to then convert this so that it can be added to a MySQL field that is of type date

How would I go about doing this in PHP?

like image 474
Zac Powell Avatar asked Oct 18 '13 21:10

Zac Powell


People also ask

How can get date in dd mm yyyy format in MySQL?

The following is the output. The following is the query to format the date to YYYY-MM-DD. mysql> select str_to_date(LoginDate,'%d. %m.

How do I convert a date from one format to another in MySQL?

In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.

How do I change the date format from Ymd to DMY?

Change YYYY-MM-DD to DD-MM-YYYY$newDate = date("d-m-Y", strtotime($orgDate));


3 Answers

$newvalue = date('Y-m-d', strtotime($originalvalue));
like image 137
Mattt Avatar answered Nov 08 '22 23:11

Mattt


MySQL displays the DATE type as 'YYYY-MM-DD', so you could do something like:

date("Y-m-d",strtotime("10/18/2013"));

like image 28
PaulV Avatar answered Nov 09 '22 01:11

PaulV


My variant:

  $mysql_date = date('Y-m-d', strtotime(str_replace('/','-', $value)));
like image 44
CreatoR Avatar answered Nov 09 '22 00:11

CreatoR