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? Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/ 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%' "; ?> Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-611543 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(); Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-611549 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. Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-613283 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, Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-613292 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(); Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-613297 Share on other sites More sharing options...
gnawz Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks alot. It is okay now. Link to comment https://forums.phpfreaks.com/topic/118756-help-on-mysql-php-dates/#findComment-613329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.