Where condition between today 19:00 and tomorrow 09:00
Where condition between today 19:00 and tomorrow 09:00
orik3ll0
Posts: 36Questions: 12Answers: 2
I need to set where condition for select between today 19:00 and tomorrow 09:00. Anyone know how to do it?
Thank you for attention and Help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Assuming you mean in javascript, there is a nice plugin call momentjs at http://momentjs.com/ that can help you with that
@bindrid thank you very much!)
Are you doing this condition on the client-side or the server-side? And what language / libraries are you using?
Allan
@allan Sorry for my late answer. I need to do something like select only today date from 19:00 till tomorrow 09:00.
->where( date("Y-m-d 19:00:00"), date("Y-m-d+1 09:00:00"), '>')
This code is wrong, but shows what exactly I need.
From the syntax given, it looks like the Editor PHP libraries. If so, you would need to use two where conditions, just like you would with an
if
statement, or in plain SQL:Allan
@tangerine I use Editor PHP libraries. I did not understand what exactly you mean client side or server side. I have 2 columns date and time. If it were sql I could do something like(Not sure that it is working good, but still explaining logic):
select * from My_Table where date BETWEEN( NOW() and NOW() + INTERVAL 1 DAY) and time between('19:00:00' and 09:00:00)
@allan
I have 2 columns 'date' and 'time'. I tried to use
->where('date', date('Y-m-d') ,'>')
->where ('time', time('19:00:00'),'>=')
Okay, it shows me all after now() and 19:00. I need to add more condition
->where('date', now()+ interval 1 day ,'>')
->where ('time', time('09:00:00'),'>=').
For example, I need to select: From :2017-04-06 19:00:00 Till: 2017-04-07 09:00:00
Sure - so use
date( 'c', time()+(60*60*24) );
.Allan
@allan ---------Php side--------
$todaydate = date('Y-m-d');
$date1 = str_replace('-', '/', $todaydate);
$tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));
$time = time('19:00:00');
-------Editor side--------
Still it is not working correct. I have 2 columns, date and time. I need to select from mysql data where date= today time=19:00 TILL date=tomorrow time=09:00.
I think from the above the two
time
columns are being given as integers rather than inHH:mm:ss
format, which I suspect the database server will need. You will need to usedate()
to format them correctly as well.Allan