Jump to content

anybody good with querying dates?


dadamssg87

Recommended Posts

thanks for the quick response. i'm a little confused where i put the start and end date of the range i want to query.

 

I'm not sure what 'field' would be in "COUNT(field)", if i obviously want to count the entire row. Also 'datetime_field'?

 

For instance let's say i have the following

<?php
$input_start = "2011-05-02";
$input_end = "2011-05-07";
$table_name = "Bookings";

 

my table structure is as follows

start 	datetime
end datetime
id int(11)
name varchar(100)

 

 

 

SELECT COUNT(field) AS cnt FROM table WHERE DATE(datetime_field) BETWEEN 'YYYY-MM-DD_start_date' AND 'YYYY-MM-DD_end_date'

Well yes this is one of those issues where you have a DATE time so when you specify a date by itself, it gets turned into the equivalent of midnight on that day.  You can rectify that by having the dates be '2011-05-02 23:59:59' or you can change those to be > and

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.