Skip to content

Instantly share code, notes, and snippets.

@thomasjao
Created January 27, 2015 06:23
Show Gist options
  • Save thomasjao/3e28434270e27e6a9a52 to your computer and use it in GitHub Desktop.
Save thomasjao/3e28434270e27e6a9a52 to your computer and use it in GitHub Desktop.
Convert date string into MySQL Date format
$origin = '97.09.27';
$dt = preg_split('/\./', $origin);
$mysqlDate = ((int)$dt[0] + 1911).'-'.$dt[1].'-'.dt[2];
1. preg_split has at least 2 parameters:
1) '/\./' -- regular expression pattern
2) $origin -- the string to be splited
it use regular expression pattern to separate the string into array
2. convert string to number (coersion)
use (int), (float), (long) before string to convert a string into number
(int)$string
3. merge number and string together to generate a new string
the string concatenate operator "." join several numbers/strings into a single string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment