PHP - Date Format Check - Page 2
Blogs > tofucake |
Dycedarg
United States12 Posts
| ||
tofucake
Hyrule18937 Posts
| ||
Pryce
Canada7 Posts
On July 24 2010 03:19 tofucake wrote: Because there are already thousands upon thousands of dates in the database. I didn't write the original site, I've come in to fix it. You should fix the dates in the database, and change the schema to use the SQL date type for columns that are meant to store dates. The database will then constrain your inputs and outputs to be sane values (which may require some input validation logic). After that's in place, you can throw the date fixing script away, as that's the type of code that shouldn't live in production code. You'll have a hell of a time unit testing it. | ||
Count9
China10928 Posts
Oh, it's already in the database LOL, that sucks. Though I'm sure there's already a date parser somewhere. Also, // for unknown d-m order assume month is firstis really sketchy >.> Also also, it's generally better to just parse the date with regex then use another process to check whether the date is valid (e.g. not 99-99-9999) cause it's not very efficient to use so many alternations, which makes the regex engine backtrack quite a bit. | ||
Cambium
United States16368 Posts
On July 24 2010 14:03 Pryce wrote: You should fix the dates in the database, and change the schema to use the SQL date type for columns that are meant to store dates. The database will then constrain your inputs and outputs to be sane values (which may require some input validation logic). After that's in place, you can throw the date fixing script away, as that's the type of code that shouldn't live in production code. You'll have a hell of a time unit testing it. Agreed completely, especially the production code point; this piece of code will be a nightmare to maintain down the road. I'd put the check at the php level or even JS level instead of relying on the db to throw exceptions. The whole thing just seems completely unnecessary. After all, user stupidity is unbound, and you can't check for everything. | ||
tofucake
Hyrule18937 Posts
| ||
| ||