Use strtotime()
on your first date then date('Y-m-d')
to convert it back:
$time = strtotime('10/16/2003'); $newformat = date('Y-m-d',$time); echo $newformat; // 2003-10-16
Make note that there is a difference between using forward slash /
and hyphen -
in the strtotime()
function. To quote from php.net:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
To avoid potential ambiguity, it’s best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
Related Posts:
- Compare given date with today
- Array to String PHP?
- How do I check if a string contains a specific word?
- how to replace quotation marks with \”
- PHP random string generator
- Is a new line = \n OR \r\n?
- Mixing a PHP variable with a string literal
- PHP: variables in strings without concatenation
- Finding the number of days between two dates
- Is there a difference between the UTC and Etc/UTC time zones?
- Multi-line strings in PHP
- How to reformat date in PHP?
- How to find the date of a day of the week from a date using PHP?
- Object of class DateTime could not be converted to string
- Convert from MySQL datetime to another format with PHP
- Convert a date format in PHP
- Uncaught Error: Call to undefined function mysql_escape_string()
- Convert DateTime to String PHP
- How can I capture the result of var_dump to a string?
- How to convert string to boolean php
- How to find the last day of the month from date?
- how to get date of yesterday using php?
- Check if URL has certain string with PHP
- What is the MM/DD/YYYY regular expression and how do I use it in php?
- Subtracting days, months or years from date using php
- Limit String Length
- How to get time difference in minutes in PHP
- Insert string at specified position
- A non well formed numeric value encountered
- PHP: date function to get month of the current date
- PHP date yesterday [duplicate]
- Remove empty array elements
- Adding days to $Date in PHP
- Calculate business days
- Replace ' and similar html codes with their correspondent character?
- Google Calendar API event update always return 404 “not found” error
- How to prevent the “Confirm Form Resubmission” dialog?
- navigate back with PHP form submission
- How to set 777 permission on a particular folder? [closed]
- How do I make a redirect in PHP?
- List of All Locales and Their Short Codes?
- Difference between “as $key => $value” and “as $value” in PHP foreach
- How do I get a YouTube video thumbnail from the YouTube API?
- What is a slug?
- Visual list of all installed fonts with respective pangram phrase?
- How to avoid Request Entity Too Large 413 error
- How to log in to phpMyAdmin with WAMP, what is the username and password?
- How do I get the current date and time in PHP?
- Should I use mysqli_real_escape string() or mysql_real_escape_string() for form data?
- How do I check if a string contains a specific word?
- count() parameter must be an array or an object that implements countable in laravel
- regex match any whitespace
- Java string to date conversion
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- Change date format in a Java string
- How to fix “Headers already sent” error in PHP
- currently unable to handle this request HTTP ERROR 500
- PHP page redirect
- How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”
- Compare two dates with JavaScript
- Whoops, looks like something went wrong. Laravel 5.0
- PHP “or” Syntax
- Fatal error: Call to undefined function mysql_connect()
- How to fix “Headers already sent” error in PHP
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- What are namespaces?
- Get the full URL in PHP
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- http://localhost:80 is not working on running Apache server through UniServer ZeroXIII
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- Mysql query- How to use contains?
- How do I get PHP errors to display?
- S_SESSION variable (user role) not recognised
- What are the main differences between PHPExcel and PhpSpreadsheet?
- Is SAJAX dead? What to replace with?
- How do I resolve a HTTP 414 “Request URI too long” error?
- Get the full URL in PHP
- PDOException: SQLSTATE[HY000] [2002] No such file or directory
- xajax expanding list query
- How to force file download with PHP
- How do I get a file extension in PHP?
- How to Set Category Page as Home Page in Prestashop
- Get the full URL in PHP
- Data source name not found, and no default driver specified
- mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
- Invalid column count in CSV input on line 1 Error
- Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in
- How to copy a file from one directory to another using PHP?
- How to check if a string starts with a specified string?
- what does PHP die() return
- Invalid column count in CSV input on line 1 Error
- Getting an error when I visit http://localhost
- How do I redirect a page in jQuery?
- mcrypt is deprecated, what is the alternative?
- How can I find my php.ini on wordpress?
- Add days to JavaScript Date
- mysqli_real_connect(): (HY000/2002): No such file or directory
- Convert a PHP object to an associative array
- XAMPP Port 80 in use by “Unable to open process” with PID 4
- PHP + curl, HTTP POST sample code?