1

This is my table:

|    date    | open  | close |
-----------------------------
| 2016-08-05 | 04:00 | 05:00 |
| 2016-05-05 | 05:00 | 06:00 |
| 2016-09-05 | 06:00 | 07:00 |

and I need to make these statements:

if ($todaydate == date && open <= $todaytime <=close) {
      // go to some link
}else{
     // failed alert
}

How do I get $todaydate and $todaytime?

Blue
  • 22,608
  • 7
  • 62
  • 92
  • Possible duplicate of [Getting current date and time in JavaScript](http://stackoverflow.com/questions/10211145/getting-current-date-and-time-in-javascript) – Polyov Aug 08 '16 at 04:46
  • 1
    Is this javascript? This looks like MySQL/PHP to me – Blue Aug 08 '16 at 04:46
  • JavaScript is a client side language, and databases usually interact with a server side scripting language. Please clarify your question, and add the necessary tags to answer your question. – Blue Aug 08 '16 at 05:03
  • hmmm, i made this code in .js file though. i use getitem ,setitem for database string. – Tanya von Degurechaff Aug 08 '16 at 05:14
  • @NamikazeSheena I've updated my answer – Blue Aug 08 '16 at 07:17

2 Answers2

3

You can do this entirely in SQL:

SELECT NOW() BETWEEN CONCAT(date, ' ', open, ':00') AND CONCAT(date, ' ', close, ':00') AS `store_is_open`
FROM `my_table`

In javascript:

var openDate = new Date(date + ' ' + open).getTime();
var closeDate = new Date(date + ' ' + close).getTime();
var now = new Date().getTime();

console.log(openDate <= now && now <= closeDate);
Blue
  • 22,608
  • 7
  • 62
  • 92
-1

You may convert stored date and time into timestamp then you can compare current timestamp to stored timestamp easily.

Mohit Tiwari
  • 165
  • 2
  • 6