convert from YY-MM-DD to MM-DD-YY in php [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL]
Right now I have DATE stored in mysql as : YY-MM-DD. EX: 2011-12-22.
How can I convert using strtotime to MM-DD-YY in php?

$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
or use the following link for the similar question
Convert date format yyyy-mm-dd => dd-mm-yyyy

Related

How to Convert Date String into Different format? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have a date that gets sent from a database which comes in a string format of '2018-01-01'. What I want to do is convert it into a string of month and year. E.G. 'January 2018'.
What would be the best way of doing so using PHP?
Try using the strtotime function to turn your string into a timestamp and the date function with the F Y format to get what you want:
$date = "2018-01-01";
$formatted = date("F Y", strtotime($date));

How to change date format dmYhis to Y-m-d in PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Convert this string to timestamp PHP [duplicate]
(2 answers)
Convert a date format in PHP [duplicate]
(18 answers)
Closed 5 years ago.
How to change date format dmYhis to Y-m-d in PHP. I have using the date() function but I cannot seem to make it work
$d = '24032017191551';
echo date('Y-m-d', strtotime($d));
Output: 1970-01-01
i want to get the ans is 2017-03-24
Below is the code to change date format
$retrieved ='24032017191551';
$date = DateTime::createFromFormat('dmYHis', $retrieved);
echo $date->format('Y-m-d');

Need to change my date format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I change the format of my date from 2016-10-05 to 10/05/2016 in php
$date= $row['date'];
So when the row echos out it'll all be the new format
Use DateTime to create an object (from the current format), allowing you to reformat the output.
$date = "2016-10-05";
$date = DateTime::createFromFormat('Y-d-m', $date);
echo $date->format('d/m/Y');
https://repl.it/DqvO

How to convert date mdy format to ymd format? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
Hi all i want to convert mdy format of date to ymd format
$todate = '03-31-2016;
I am using this code to convert it
$todate = date("Y-m-d", strtotime($todate));
This code gives me output
1969-12-31
so whats the right way to do it?
Thanks
Try this code
$date = '03-31-2016;
$todate = date("Y-m-d", strtotime($date));

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

This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
PHP mysql insert date format
(11 answers)
Closed 9 years ago.
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?
$newvalue = date('Y-m-d', strtotime($originalvalue));
MySQL displays the DATE type as 'YYYY-MM-DD', so you could do something like:
date("Y-m-d",strtotime("10/18/2013"));
My variant:
$mysql_date = date('Y-m-d', strtotime(str_replace('/','-', $value)));
$date = preg_replace('/(\d{2})\/(\d{2})\/(\d{4})/', '$3-$1-$2', $date)

Categories