|
Posted by Michael Fesser on 10/27/07 18:01
..oO(larry@portcommodore.com)
>I prefer to store my dates in YYYYMMDD format on my tables for
>compactness and readability
This is not a problem as long as a proper date type is used in the table
(DATE or DATETIME for example). In MySQL dates are stored as YYYY-MM-DD
strings, but YYYYMMDD is also possible in a numeric context.
>and worked up a bunch of functions for
>working with them
Looks pretty complicated. MySQL and PHP have a lot of date functions,
which already can do most of that. With properly stored dates such
calculations are as easy as adding two integers. MySQL is also able to
return Unix timestamps, which can then easily be used with PHP's date
functions.
>function datestringtonum($input, $lowyear = 1920, $maxyear = 2300 ) {
> $sdate = "";
> // convert possible YYYYMMDD entry to MM/DD/YYYY string
> if($input > 10000000 and $input < 99999999){
> $input = datenumtostring($input);
> }
> // split date based on different seperators
> if ( strpos($input,"/") != 0) { // if seperators are '/'s...
> $sdate = explode("/",$input);
> } else if ( strpos($input,"-") != 0) { //if seperators are '-'s
> $sdate = explode("-",$input);
> [...]
You might want to consider to use regular expressions, which makes it
very easy to test against different patterns.
Micha
Navigation:
[Reply to this message]
|