Jump to content

select beetween 2 times .... help please


Recommended Posts

hello, I wont select the record with the following conditions ... I have 4 fields with time opening and closing hours morning and afternoon hours opening and closing ...

Time format: 24 hours

 

egsemple mysql records (fields in the db I have tried set as varchar and as time):

 

$monday_time1= '08:30'; // db record

$monday_time2= '12:30'; // db record

$monday_time3= '20:30'; // db record

$monday_time4= '23:30'; // db record

$k = 'close'; db record 

 

------------------------------------my actual code:

$idtime = "03:00";   //variable

$sql1 = mysql_query("select * from dat where $k <> '1' and ($monday_time1 != 'k' and $monday_time1 <= '$idtime' and $monday_time2 >='$idtime') or ($monday_time3 <= '$idtime' and $monday_time4 >='$idtime')")or die ("Errore: ". mysql_error());

 

but this not work well... also select records that are not present at certain times... where i error ?

 

sorry for my bad english ....

Link to comment
https://forums.phpfreaks.com/topic/185348-select-beetween-2-times-help-please/
Share on other sites

hello, I wont select the record with the following conditions ... Ihave 4 fields with time opening and closing hours morning and afternoonhours opening and closing ...

Time format: 24 hours

 

egsemple mysql records (fields in the db I have tried set as varchar and as time):

 

$monday_time1= '08:30'; // db record

$monday_time2= '12:30'; // db record

$monday_time3= '20:30'; // db record

$monday_time4= '23:30'; // db record

$k = 'close'; db record 

 

------------------------------------my actual code:

$idtime = "03:00";  //variable

 

$sql1= mysql_query("select * from dat where $k <> '1' and($monday_time1 != 'k' and $monday_time1 <= '$idtime' and$monday_time2 >='$idtime') or ($monday_time3 <= '$idtime' and$monday_time4 >='$idtime')")or die ("Errore: ". mysql_error());

 

but this not work well... also select records that are not present at certain times... where i error ?

 

sorry for my bad english ....

 

no i am saying as u have given as k in the query..

for the variables u should run as $k,

i think that is wrong the query.

 

What do you want to achieve with this code? Get the closing and opening hours of a store?

 

+-----------+--------------------------------------------+
| day       | opening_hours                              |
+-----------+--------------------------------------------+
| Monday    | 8.30 till 11.30 and 13.00 till 17.00       |
| Tuesday   | 8.30 till 11.30 and 13.00 till 17.00       |
| Wednesday | 8.30 till 11.30 and 13.00 till 17.00       |
| Thursday  | 8.30 till 11.30 and 13.00 till 17.00       |
| Friday    | 8.30 till 11.30 and 13.00 till 17.00       |
| Saturday  | 8.30 till 11.30                            |
+-----------+--------------------------------------------+

 

Keep it simple let the user define the closing and opening hours.

this is my db:

 

or.jpg

 

 

 

$monday_time1= '08:30'; // db record  $lp1    //morning

$monday_time2= '12:30'; // db record  $lp2    //morning

$monday_time3= '20:30'; // db record  $lp3    //afternoon

$monday_time4= '23:30'; // db record  $lp4    //afternoon

 

hio ignace ... yes, i wont achieve closing and opening hours of a store ... I would select a time (eg: 15:00) according to which I will leave all the shops open at that hour

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.