hoopplaya4 Posted November 10, 2008 Share Posted November 10, 2008 Here's an easy question (I think). Is it possible, when doing a MySql Query to include a date() string? For instance, if I'm doing: SELECT * FROM table WHERE field LIKE Would it be possible to enter in something like "date(Y) after "LIKE?" If so, what is the syntax? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/ Share on other sites More sharing options...
gaza165 Posted November 10, 2008 Share Posted November 10, 2008 you can do something like.... $sql = "SELECT * FROM table WHERE MONTH(field) LIKE MONTH(date_field)" Quote Link to comment https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/#findComment-686739 Share on other sites More sharing options...
The Little Guy Posted November 10, 2008 Share Posted November 10, 2008 Something like so? $mDate = date('Y'); $sql = mysql_query("SELECT * FROM table WHERE field LIKE '$mDate%'"); while($row = mysql_fetch_array($sql)){ echo $row['field'].'<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/#findComment-686740 Share on other sites More sharing options...
flyhoney Posted November 10, 2008 Share Posted November 10, 2008 If you need to get really specific about dates you can use this approach: <?php $sql = " SELECT COUNT(id) as total FROM table WHERE date >= FROM_UNIXTIME(".mktime(0, 0, 0, date("m"), date("d"), date("Y")).") "; ?> There might be a better way, but I've used this to find things like, "How many people registered this week?" or, "How many uploads have there been today?", etc... Quote Link to comment https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/#findComment-686747 Share on other sites More sharing options...
hoopplaya4 Posted November 10, 2008 Author Share Posted November 10, 2008 Those are all great examples. Thanks for the help. I knew there was a way, I just needed to know how to go about doing it. Take care. Quote Link to comment https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/#findComment-686748 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.