hassank1 Posted January 19, 2009 Share Posted January 19, 2009 I want to select from a datetime field where the date = today .. (I don't care what time of the day) .. how can I do that ? Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/ Share on other sites More sharing options...
Mchl Posted January 19, 2009 Share Posted January 19, 2009 WHERE dateTimeField = DATE(NOW()) Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-740310 Share on other sites More sharing options...
fenway Posted January 19, 2009 Share Posted January 19, 2009 You can actually just use NOW()... no need for wrapping in DATE(). Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-740330 Share on other sites More sharing options...
hassank1 Posted January 19, 2009 Author Share Posted January 19, 2009 I guess Now() will take the time into consideration Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-740339 Share on other sites More sharing options...
Mchl Posted January 19, 2009 Share Posted January 19, 2009 Yes... and I screwed up WHERE DATE(dateTimeField) = DATE(NOW()) Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-740343 Share on other sites More sharing options...
fenway Posted January 19, 2009 Share Posted January 19, 2009 Yes... and I screwed up WHERE DATE(dateTimeField) = DATE(NOW()) In fact, mysql is quite lax, and will happily match up date with date/time fields even without DATE() wrapping. Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-740401 Share on other sites More sharing options...
Mchl Posted January 20, 2009 Share Posted January 20, 2009 I disagree. DROP TABLE IF EXISTS `dateTable`; CREATE TABLE `dateTable` ( `d` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`d`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `dateTable` VALUES (NOW()); SELECT d FROM `dateTable` WHERE d = DATE(NOW()); -- 0 rows returned SELECT d FROM `dateTable` WHERE DATE(d) = DATE(NOW()); -- 1 row returned Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-741322 Share on other sites More sharing options...
fenway Posted January 20, 2009 Share Posted January 20, 2009 Sorry, I missed what was going on here... I thought you were comparing a DATE field to NOW(). FYI, it's easier to use: SELECT d FROM `dateTable` WHERE d = CURDATE(); Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-741580 Share on other sites More sharing options...
Mchl Posted January 21, 2009 Share Posted January 21, 2009 Heh... yeah, it probably is Forgot abut this function. Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-741940 Share on other sites More sharing options...
fenway Posted January 21, 2009 Share Posted January 21, 2009 Heh... yeah, it probably is Forgot abut this function. Actually, I use it to be explicit -- CURDATE() when I'm just comparing the date, vs. NOW() when I mean the full date & time. Just a convention of mine, but it helps. Link to comment https://forums.phpfreaks.com/topic/141424-where-date-today/#findComment-742604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.