Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date into US formatting in PHP? [duplicate]

Tags:

php

Possible Duplicate:
PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL]

Hope everyone is having a great holiday.

I have a date in this format: 23-12-2011 and would like to reverse it into US format 2011-12-23.

Does anyone know how I can do this in PHP? Is there any function for breaking strings up?

like image 528
Helen Neely Avatar asked Dec 23 '11 10:12

Helen Neely


People also ask

How do I change date format from YYYY-MM-DD in PHP?

In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate));

How convert date from yyyy-mm-dd to dd-mm-yyyy format in PHP?

How convert date from yyyy-mm-dd to dd-mm-yyyy format in PHP? Answer: Use the strtotime() Function You can first use the PHP strtotime() function to convert any textual datetime into Unix timestamp, then simply use the PHP date() function to convert this timestamp into desired date format.

How do I convert a date format to another format?

Select the column of dates you want to convert to another locale. Press Ctrl+1 to open the Format Cells. Select the language you want under Locale (location) and click OK to save the change.

What does Strtotime mean in PHP?

Definition and Usage The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.


1 Answers

$date = DateTime::createFromFormat('d-m-Y', '23-12-2011');
echo $date->format('Y-m-d');

Voila. Check out PHP5s datetime class

like image 157
Flukey Avatar answered Nov 02 '22 22:11

Flukey