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.
Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.