Re: [PHP] Selecting all records between a date range



On Thu, Oct 2, 2008 at 12:35 PM, Jason Pruim <japruim@xxxxxxxxxx> wrote:
Hi Everyone,

I am working on a app where I need to be able to select all the values from
a database where the 'timein' field is between a certain date range...
Essentially the last 7 days...

here is the code that I am working with:

$rangeBegin = strtotime("Last week thursday midnight");
$rangeEnd = strtotime("Today now");


$SQLTEST = "SELECT * FROM `timeStore` WHERE `timein` BETWEEN
{$rangeBegin} AND {$rangeEnd}";
echo "SQLTEST: " . $SQLTEST . "<br>";
SQLTEST: SELECT * FROM `timeStore` WHERE `timein` BETWEEN
1222315200 AND 1222920000
Could not perform query: Query was empty

All of my times are stored as unix timestamps in the database, such as:

+------------------------------------------+
| timein | timeout | empID | record |
+------------+------------+-------+--------+
| 1222354037 | 1222382837 | 1 | 107 |
| 1222440437 | 1222469237 | 1 | 108 |
| 1222526837 | 1222555637 | 1 | 109 |
| 1222613237 | 1222642037 | 1 | 110 |
| 1222699637 | 1222728437 | 1 | 111 |
| 1222359217 | 1222359220 | 2 | 115 |
| 1222359214 | 1222359220 | 2 | 114 |
| 1222359219 | 1222359220 | 2 | 116 |
| 1222359231 | 1222359566 | 2 | 117 |
+------------------------------------------+

Anyone has any ideas? Or maybe a better way? :)

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
japruim@xxxxxxxxxx







You can do this:

$startTS = time() or mktime for today at midnight
strtotime("-1 week", $startTs)

and make your query use these params.
.



Relevant Pages

  • Selecting all records between a date range
    ... I am working on a app where I need to be able to select all the values from a database where the 'timein' field is between a certain date range... ... Could not perform query: Query was empty ...
    (php.general)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: OT: SQL
    ... query processing. ... FROM Employees e, Employees m, Management mgt ... Manager and Employee Salaries. ... The scheme used does not model database files in general, ...
    (sci.logic)
  • Re: access 2003
    ... I removed the parameters from the form query source. ... boxes from the form header, events, code, etc and ran the form query source ... forms queries and the SQL because syntax of the SQL will change randomly. ... the Access 97 database, I wouldn't have thought any expressions would be ...
    (microsoft.public.access.conversion)
  • RE: Import external data - web query
    ... Your reply for my query is very extensive, this is for importing a file from ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)