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
- PHP “or” Syntax
- Invalid column count in CSV input on line 1 Error
- How to check if a string starts with a specified string?
- mysqli_real_connect(): (HY000/2002): No such file or directory
- $wpdb->update or $wpdb->insert results in slashes being added in front of quotes
- Are there dictionaries in php?
- laravel updateOrCreate method
- How to listen messageSent event in laravel 5.5
- How to insert an item at the beginning of an array in PHP?
- PHP Deprecated: Methods with the same name
- How do I pass JavaScript variables to PHP?
- Call to undefined function curl_init().?
- How to verify password against database?
- what is a good method to sanitize the whole $_POST array in php?
- Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)
- Convert date to datetime in Python
- Difference between $_SERVER[‘DOCUMENT_ROOT’] and $_SERVER[‘HTTP_HOST’]
- How do I get the day of week given a date?
- Refresh a page using PHP
- Laravel 5.2 Storage::makeDirectory($dir) is not creating directory
- Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- PDO closing connection
- “Valid CSRF Token Required” in Osticket After login?
- Child theme css not overriding parent
- Convert timestamp to readable date/time PHP
- Creating a php search bar
- What does ‘=' mean in PHP?
- Parsing domain from a URL
- PHP class not found but it’s included
- How to fix the session_register() deprecated issue?
- PHP to write Tab Characters inside a file?
- Are There Any Cron Jobs Alternative?
- How to Create Multiple Where Clause Query Using Laravel Eloquent?
- PHP: How to get referrer URL?
- Warning: A non-numeric value encountered
- Proper Format of iframe in PHP?
- php_network_getaddresses: getaddrinfo failed: Name or service not known (0) Failed To Connect..!
- Composer: Command Not Found
- Ruby String to Date Conversion
- Convert normal date to unix timestamp
- Undefined variable: $_SESSION
- Error:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
- The character encoding of the HTML document was not declared
- Notice: Undefined offset: 0 in
- How to Sort a Multi-dimensional Array by Value
- How to write a link like which link to the same page in PHP?
- PHP + JQuery – How to use these two together? Please see my example
- Data extraction from /Filter /FlateDecode PDF stream in PHP
- How to use data-saferedirecturl in a tag in PHP?
- Clear cache in Symfony: `cache:clear` or `rm -rf`?
- create php live clock
- Converting a UNIX Timestamp to Formatted Date String
- PHP Call to undefined function
- Formatting a number with leading zeros in PHP
- How to convert java.util.Date to java.sql.Date?
- POST an array from an HTML form without javascript
- WP_Query meta_query results date by date
- display month in french in wordpress/php?
- Get date numerical and separate?
- How to manually change current date to post date in frontend?
- Get posts from year from URL
- Can’t add to time? [closed]
- Grouping posts by date
- Get month and day from a Date Picker custom field
- Convert custom field date format to “WordPress default”