Where condition between today 19:00 and tomorrow 09:00

Where condition between today 19:00 and tomorrow 09:00

orik3ll0orik3ll0 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

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    Assuming you mean in javascript, there is a nice plugin call momentjs at http://momentjs.com/ that can help you with that

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    @bindrid thank you very much!)

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin

    Are you doing this condition on the client-side or the server-side? And what language / libraries are you using?

    Allan

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    @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.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Are you doing this condition on the client-side or the server-side? And what language / libraries are you using?

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin

    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:

    ->where( 'fieldName', date1, '>' )
    ->where( 'fieldName', date2, '<' )
    

    Allan

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    @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)

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    @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

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin

    now()+ interval 1 day

    Sure - so use date( 'c', time()+(60*60*24) );.

    Allan

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2
    edited April 2017

    @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--------

    ->where('date',$todaydate ,'>=')
    ->where ('time', $time,'>=')
    ->where('date', $tomorrow, '<=')
    ->where('time',time()+(60*60*14) ,'<=')
    

    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.

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin

    I think from the above the two time columns are being given as integers rather than in HH:mm:ss format, which I suspect the database server will need. You will need to use date() to format them correctly as well.

    Allan

This discussion has been closed.