[thelist] date time calculation query

Bob Meetin bobm at dottedi.biz
Tue Sep 20 16:58:21 CDT 2011


I am writing a query against an existing database/table in which I need to qualify whether the member's subscription is active. Typically when I write these types of queries the 2 dates are in some date type, but here they are int(11) and I presume that the number is relevant to some date from point in time, but of course I'm unfamiliar with this method of doing calculations.

The values:

+----+---------+---------------+------------------+----------------+
| id | user_id | membership_id | membership_start | membership_end |
+----+---------+---------------+------------------+----------------+
|  1 |      62 |             2 |       1316571958 |     1319163958 |
|  2 |      62 |             1 |       1316572508 |     1319164508 |
+----+---------+---------------+------------------+----------------+
2 rows in set (1.23 sec)

The relevant fields:

mysql> desc membership_users;
+---------------------+---------------+------+-----+---------+----------------+
| Field               | Type          | Null | Key | Default | Extra          |
+---------------------+---------------+------+-----+---------+----------------+
| id                  | int(11)       | NO   | PRI | NULL    | auto_increment |
| user_id             | int(11)       | NO   | MUL | NULL    |                |
| membership_id       | int(11)       | NO   |     | NULL    |                |
| membership_start    | int(11)       | NO   |     | NULL    |                |
| membership_end      | int(11)       | NO   |     | NULL    |                |
+---------------------+---------------+------+-----+---------+----------------+

Given the user_id I need to determine if the current date/time is between the start/end and if so, set some variable in PHP to TRUE, say $access = TRUE.  Advice please...

-- 
Bob



More information about the thelist mailing list