oli_62 Posted April 18, 2006 Share Posted April 18, 2006 HelloI 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 Quote Link to comment https://forums.phpfreaks.com/topic/7732-select-date-range-from-timestamp-with-php-and-mysql/ Share on other sites More sharing options...
wisewood Posted April 18, 2006 Share Posted April 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7732-select-date-range-from-timestamp-with-php-and-mysql/#findComment-28210 Share on other sites More sharing options...
oli_62 Posted April 18, 2006 Author Share Posted April 18, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7732-select-date-range-from-timestamp-with-php-and-mysql/#findComment-28265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.