Monday 15 September 2014

Prevent double booking check using PHP / MySQL datetime -



Prevent double booking check using PHP / MySQL datetime -

struggling lesson booking sys creating. have date in db named lesson_date_time , uses mysql datetime , each lesson lastly set number of minutes. (i not storing end date minutes vary.)

to prevent double bookings datetime stored plus required minutes, can't seem figure out sql check see if period of time exists

i have...

$mins = "60"; $date_start = "2014-10-30 12:40:00"; $date_end = date("y-m-d h:i:s", strtotime("$date_start + $mins minute")); lesson_date_time between cast('$date_start' datetime) , cast('$date_end' datetime)

this check , kinda works not grab entries have start date in hr (or period of time until end date) after $start_date.

also tried

where lesson_date_time >= '$date_start' , lesson_date_time =< '$date_end

which not find results though exit.

is possible want or easier if store lesson end time , go there

your between

where lesson_date_time between cast('$date_start' datetime) , cast('$date_end' datetime)

would equivilent to

where lesson_date_time >= cast('$date_start' datetime) , lesson_date_time <= cast('$date_end' datetime)

this still won't work since looking lessons start during lesson. won't ones continuing lesson. those, have store end date (easier) or store lesson length.

if lessons 60 minutes long, like.

$mins = "60"; $date_start = "2014-10-30 12:40:00"; $old_lesson_start = date("y-m-d h:i:s", strtotime("$date_start - $mins minute")); $date_end = date("y-m-d h:i:s", strtotime("$date_start + $mins minute")); lesson_date_time between cast('$old_lesson_start' datetime) , cast('$date_end' datetime)

then, grab lessons started 60 minutes ago , continuing lesson.

if decide store lengths or end dates, can help sql if have problems it.

php mysql datetime

No comments:

Post a Comment