Jump to content

Archived

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

oli_62

Select date range from timestamp with php and mysql

Recommended Posts

Hello

I want make a database query with a date range (e.g. 01.01.2006-01.03.2006). I set on each Insert statement a timestap. And this select command should list only the entries within this date range.

Any ideas?

Thanks oli

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.