My question is compare the record between <=
and >=
my table contain columns ID,Name,Address,Stacks,StartDateTime,EndDateTime. I want to fetch record between StartDateTime
and EndDateTime
. DateTime Format is 0000-00-00 00:00:00
mysql-> Select * from Table_nm where StartDateTime>= $DATETIME and EndDateTime<= $DATETIME1;
So,my question is How I compare records that,
1. $DATETIME= 2015-02-03 10:00:00 and $DATETIME1 =2015-02-06 20:00:00
2. $DATETIME= 2015-02-03 05:00:00 and $DATETIME1 =2015-02-06 13:00:00
3. $DATETIME= 2015-02-03 10:00:00 and $DATETIME1 =2015-02-06 11:00:00
like wise records contains datetime, so ,Give me results for filter shown below.
1.If I want to filter record where StartDateTime>=2015-02-03 00:00:00 and EndDateTime<= 2015-02-06 00:00:00.
2.If I want to filter record where StartDateTime>=2015-02-03 09:00:00 and EndDateTime<= 2015-02-06 12:00:00.
3.If I want to filter record where StartDateTime>=2015-02-03 01:00:00 and EndDateTime<= 2015-02-06 22:00:00.
and How this filter for works for DateTime >=
and <=
, Please help!
I use TIMESTAMPDIFF
In your example, it would be something like:
mysql-> Select * from Table_nm
where TIMESTAMPDIFF(SECOND, `StartDateTime`, '$DATETIME')>= 0
and TIMESTAMPDIFF(SECOND, `EndDateTime`, '$DATETIME1')<= 0;