Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ACTUAL CODE I HAD TO WRITE BECAUSE PHP'S DATE PARSING IS GFXJDNVJVXJHZGVFHDSVXFHZFHSZDBMDBGMNGDFCVNG
<?php
/**
* Convert a date to the "American" date format.
*
* While one may assume this function appropriately rearranges the
* date format to follow the American MM/DD/YYYY format, in reality
* and by intention, this function is very naive. All it does is replace
* all dashes and periods with a forward-slash, preserving all ordering
* and leaving that up to the caller.
* This behavior is to allow PHP to correctly parse dates in the American
* format, as it foolishly uses the delimiter to determine the parse format
* rather than using the data in the string.
*
* @see {http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes|Third note box}
* @param {string} $date - Any acceptable date format.
* @returns {string} The same date format but with forward-slash deliminators.
*/
function convertToAmericanDate($date) {
return str_replace(['-', '.'], '/', $date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.