Re: Datetime within past week



Greg Scharlemann wrote:
I have a series of records in a database. When each record is stored,
the datetime is logged: $date = date("Y-m-d H:i:s");

Prior to adding a new record to the database, I want to run a query to
retrieve all of the records uploaded in the last 7 days. I thought it
would be easiest to:

Pseudo Code:
$newDate = $date - 7 days;
select * from TABLE where DATE > $newDate;

Problem is I can't figure out how to subtract 7 days from $date and
convert that value to a valid datetime object.

Thanks for any help


If it's MySQL, you can do it all in SQL:

$result = mysql_query('SELECT myColumn FROM myTable where datacol= SUBDATE(NOW(), INTERVAL 7 DAY))';

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Internet class differences...
    ... The database and web interface to the server is produced by a different ... Initially a WebClient class was used. ... This worked fine for submitting the query. ... retrieve the results but, instead, is sent to a login page from which it ...
    (microsoft.public.dotnet.general)
  • Re: Drilltrough Question
    ... not query the underlying relational database, ... that in AS2000 drilllthrough queries retrieved data from the underlying ... I could retrieve any column from any table in the ...
    (microsoft.public.sqlserver.olap)
  • Re: How can I reduce the number of queries to my PostgreSQL database?
    ... SR> all books in the database, and all authors for each book. ... retrieve a list of all book_ids and book_titles. ... That's one query, if you're willing to make it advanced enough, ... although you need to make an aggregate to enable PostgreSQL to ...
    (comp.lang.python)
  • Re: Need help improving authorization
    ... >roles stored in the database. ... Currently, I retrieve the the ... >I think a more efficient approach would be to query the database only once ... >a delimied string and stored in cookie or a session variable. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Find text in SQL
    ... form/control-related queries. ... Access retains all the prior queries. ... I did simply import all to a new database, ... > database as a query named something along those lines. ...
    (microsoft.public.access.modulesdaovba)