Jump to content

Select date range from timestamp with php and mysql


oli_62

Recommended Posts

I have this very same thing on my intranet system.

I used the mktime() function.

if you want to search between 2006-18-04 16:40:22 and 2006-19-04 16:40:22 (between now and this time tomorrow) you would use this

[code]
<?php
$start = mktime(16, 40, 22, 04, 18, 2006);
$end = mktime(16, 40, 22, 04, 19, 2006);

$query = "SELECT * FROM your_table WHERE time_stamp > $start AND time_stamp < $end";

// etc etc etc
?>
[/code]

This will select from your_table all entries where the time_stamp field is greater than the timestamp for the $start variable and less than that timestamp for the $end variable.

Hope this helps you on your way.
Thanks it seems to work.


I modified it a bit!

[code]
<?php
$start = mktime(16, 40, 22, 04, 18, 2006);
$end = mktime(16, 40, 22, 04, 19, 2006);

$query = "SELECT * FROM your_table WHERE time_stamp => $start AND time_stamp =< $end";

// etc etc etc
?>
[/code]

With the equal before the greather or smaller character lists also the day of the var ($start or $end).

oli

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.