Sorry I should have included a simple example:

SELECT (`field_01`, `field_02`) FROM `table` WHERE DATETIME('2009-09-01 00:00:00.000') < DATETIME('2009-10-01 23:59:59.999');

Dan Shirah wrote:
Hi All,

I have a DB that is storing the date/time an event happens in DATETIME
format, i.e. 1254252889, which translates to Tue, 29 Sep 2009 19:34:49 UTC

I am trying to write a query in PHP that will look for any row that falls
within a range of dates, i.e. between Sep 1 and Oct 1, but there doesn't
seem to be a way to search, since you would never be able to specify a match
between what date range you put in, and the time stamps??

I created a form that allows them to select a date, but even converting a
date string to a timestamp, you'll never be able to get a match in the

Any thoughts appreciated,


I'm not sure I'm following you.

1) What database are you using?  MSSQL/Informix/MySQL?

2) The data type for your event date/time column is just DATETIME?  Or is it
DATETIME YEAR TO FRACTION or anything like that?

3) Wouldn't your query be written in SQL and just executed from PHP?

If you are using DATETIME YEAR TO FRACTION your query should look something

"SELECT * FROM my_table WHERE event_date BETWEEN ('2009-09-01 00:00:00.000'
AND '2009-10-01 23:59:59.999')"

Jason Gerfen
Systems Administration/Web application development

Marriott Library
Lab Systems PC
295 South 1500 East
Salt Lake City, Utah 84112-0806
Ext 5-9810

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to