I am using a FormValidaitor class to make sure form elememts are correct before insert into mySQL
I have two date fields which have been created from drop downs and concatenated into the mySQL format for insertion so I know the date will is be correctly formatted.
As one is a start and one is an end date I would like to compare to the two and make sure that $StartDate <= StartDate. I have difficulty getting it to work. Obviously I would love the answer, but really I would like to find out how to do it from scratch :).
Can dates be treated in this way? Is there a magic function to compare dates? I have spent a while looking for and answer to this online but maybe there is a good resource I dont know of?
Two things occurr to me as possibilities. If MySQL supports database constraints, you might do something like
alter table MyTable add constraint MyDateConstraint (StartDate <= EndDate)
Most databases allow dates to be compared like that, IIRC. The drawback, of course, is that if the transaction isn't allowed because of that constraint you don't necessarily know why. (At least, not with the level of error checking I usually do on database queries. A bit more work could dig out not just whether it succeeded but if not, why.)
The other thing I might do would be to use the strftime() function to get a Unix timestamp for each date in question. Timestamps are just integer numbers of seconds, so you can compare them with normal comparison operators.