comparing date value of two separate columns
I have two separate columns within the same table in my database. Both of them store date in this format (2010-10-06T13:00:00). I also have a drupal form which I am trying to validate. It collects collects starttime and endtime values from the user and stores it in the database. What I am trying to do is to make sure that the time (starttime && endtime) entered by the user does not already exist in the database. The code below is what I have so far but no success..
function taxonomy_conflict_validate(&$form, $form_state) {
$starttime = $form_state[values][field_roomequip_date][0][value];
$endtime = $form_state[values][field_roomequip_date][0][value2];
if (mysql_num_rows(db_query("SELECT * FROM
content_type_equiproom WHERE
field_roomequip_date_value BETWEEN '$startime' AND '$endtime'
AND field_roomequip_date_value2 BETWEEN '$startime' AND '$endtime'")))
{
form_set_error("Date", t("The time specified is no longer available"));
}
}
开发者_JAVA百科
You may have already had this question answered but i would like to share a useful resource, that may help you in the future. Finding available reservation periods
This sounds like the type of thing that you are after, the website in particular is a model of common queries for MySQL that has loads of common things that you may need to achieve. An invaluble resource in my opinion.
精彩评论