PHP Date Range Query

Posted on 2007-08-01
Last Modified: 2013-12-12
having an issue with this, hopefully someone can straighten me out.

SELECT * FROM notes WHERE timestamp BETWEEN ".$_REQUEST[start]." and ".$_REQUEST[end]." ORDER BY timestamp desc

timestamp records contain data as 2007-06-03 13:25:47

I'm not getting any results out of this (and I should), so any assistance would be greatly appreciated
Question by:mopar003
    LVL 24

    Accepted Solution

    Are you sure that your  $_REQUEST is populated? Try printing out the query before running it. Then copy/paste the query into the query browser to make sure that it should, in fact, be finding something.

    The data format should be escaped with quotes.

    i.e..... BETWEEN '2006-05-13 03:45:23' and '2006-05-17 01:25:23'
    LVL 24

    Expert Comment

    sorry, I meant that the DATE format should be enclosed with quotes.
    LVL 1

    Author Comment

    I think that was part of it, but i may have tried that as well.  At the time I was using a $_REQUEST[end] field, which may have been the actual culprit, being that end is a reserved word in PHP.  I changed it to enddate and added the quotes and allis well.  Thanks for the help.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now