Skip to content

Instantly share code, notes, and snippets.

@le717
Created November 5, 2016 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le717/e4f7592be65824417a93daf53ca1b777 to your computer and use it in GitHub Desktop.
Save le717/e4f7592be65824417a93daf53ca1b777 to your computer and use it in GitHub Desktop.
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