I am working on a project where admin can book an building unit for a customer.And i require that a month lie between two dates of booking or not for calendar.I am using query for this is

"SELECT * FROM rt_booking WHERE rt_unit_id='".$urow['rt_unit_id']."' AND rt_start_date<=".$date11." AND rt_end_date<=".$date22;

Here rt_start_date(unixtimestamp) and rt_end_date(unixtimestamp) is the booking start and end dates.and date11(unixtimestamp) and date22(unixtimestamp) is month starting date and month ending date for a caledar month.
It is working well if the booking start date(rt_start_date) is less more than one month with starting month date(date11) and booking ending date is greater than month ending date.
But if booking date is from 15 january 2012 to 20 january 2012 then it should be selected with for month 'january' from date11=strtotime(01-01-2012) and month end strtotime(31-01-2012);

Recommended Answers

All 4 Replies

Member Avatar

months are the trickiest of all comparisons!

Use the YEAR_MONTH function. Like:


This will get '201302' for today's date.

how can i use it in query.

how can i use it?

thank you diafol to solve my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.