gnawz Posted August 8, 2008 Share Posted August 8, 2008 Iam using PHP 5.2.3 and My SQL 5.0.45 I need to select database details where the date is today. My MYSQL date type is DATETIME. I know if my MYSQL date type is DATE I do it thus; <? $sql = 'SELECT * FROM cstocksales WHERE Date = CURRENT-DATE'; ?> AND it works But how do I do it with a date data type that is DATETIME, ie return results with current data and its time when a sle was made? Quote Link to comment Share on other sites More sharing options...
alin19 Posted August 8, 2008 Share Posted August 8, 2008 i didn't understand exactly what did you want to do <?php $date=date("Y-m-d"); $sql = "SELECT * FROM cstocksales WHERE Date like '%$date%' "; ?> Quote Link to comment Share on other sites More sharing options...
toivo Posted August 8, 2008 Share Posted August 8, 2008 - or try something like this: ... WHERE DATE_FORMAT(Date, '%Y%m%d') = CURDATE(); Quote Link to comment Share on other sites More sharing options...
gnawz Posted August 11, 2008 Author Share Posted August 11, 2008 I need to do the comparison (generate a report) from a MySQL date field whose data type is DATETIME.. Meaning it displays date and time as opposed to data type DATE which displays only the date. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted August 11, 2008 Share Posted August 11, 2008 you can do that using: ... WHERE `Date` = NOW() ... did i get your point? jay, Quote Link to comment Share on other sites More sharing options...
toivo Posted August 11, 2008 Share Posted August 11, 2008 I need to do the comparison (generate a report) from a MySQL date field whose data type is DATETIME.. Meaning it displays date and time as opposed to data type DATE which displays only the date. Did you try it? My example compares dates, not times: ... WHERE DATE_FORMAT(Date, '%Y%m%d') = CURDATE(); Quote Link to comment Share on other sites More sharing options...
gnawz Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks alot. It is okay now. Quote Link to comment 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.