Start and End Date Validation
Try using Magento's validator's validate-date-range
class on your fields.
If you add this to both fields then it will get the to date and compare the two values.
If get the to date value using the following code:
var m = /\bdate-range-(\w+)-(\w+)\b/.exec(elm.className);
if (!m || m[2] == 'to' || Validation.get('IsEmpty').test(v)) {
return true;
}
So what you will need to do is add a class in the format date-range-your_attribute_code-from
and date-range-your_attribute_code-to
. Doing this will mean that Magento is able to link the two fields.
For an example of this check out the design tab on CMS pages. app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php
The following is a more detailed explanation about the classes:
validate-date
: this makes sure that the entered value is a valid date,validate-date-range
: this does the comparison between two dates when the have the correct classes,date-range-custom_data-from
,date-range-custom_data-to
: these link the two dates so that they can be used in the date range check, note that these should be the same apart from the-to
and-from
means it can bedate-range-xxxx-from
anddate-range-xxxx-to
respectively.