ramiwahdan Posted March 10, 2020 Share Posted March 10, 2020 Hi, I have a table field that has the full timestamp (date and time), I want to select records from DB but after checking the date part only from the timestamp. Example: 2020-3-10 10:15:00 ---- i want to check if current date is equal to the date part which in this case it is the same. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/ Share on other sites More sharing options...
ramiwahdan Posted March 10, 2020 Author Share Posted March 10, 2020 I tried this but it is not getting the date from the timestamp: $testDate = date($row2['ClockingInDate']); $curdate = date("Y-m-d"); I am still getting the full date and time for the first variable! Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575323 Share on other sites More sharing options...
ramiwahdan Posted March 10, 2020 Author Share Posted March 10, 2020 (edited) 17 minutes ago, ramiwahdan said: I tried this but it is not getting the date from the timestamp: $testDate = date($row2['ClockingInDate']); $curdate = date("Y-m-d"); I am still getting the full date and time for the first variable! I tried a better one but i am getting the default value of 1970: $testDate= date('Y-m-d',$row2['ClockingInDate']); $curdate = date("Y-m-d"); testDate is getting the default value of 1970...why is that? Edited March 10, 2020 by ramiwahdan update with screen shot Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575324 Share on other sites More sharing options...
maxxd Posted March 10, 2020 Share Posted March 10, 2020 Where is ClockingInDate coming from? You mention a timestamp and a timestamp from db - what is where, and what data does everything contain? Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575333 Share on other sites More sharing options...
cyberRobot Posted March 10, 2020 Share Posted March 10, 2020 Are you using MySQL? If so, have you tried the built-in date functions to get the needed information? More information about the functions can be found here:https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575336 Share on other sites More sharing options...
ginerjm Posted March 10, 2020 Share Posted March 10, 2020 Show us your query. The way I would do this would be to use a mysql function to only select the yyyy-mm-dd portion of the timestamp and compare it (in the where clause) to the exact yyyy-mm-dd value you want to find. To be clear - I would do this IN the query statement itself. Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575339 Share on other sites More sharing options...
Barand Posted March 10, 2020 Share Posted March 10, 2020 SELECT whatever FROM mytable WHERE DATE(timestamp) = CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575340 Share on other sites More sharing options...
chhorn Posted March 12, 2020 Share Posted March 12, 2020 Or SELECT DATE(timestamp) = CURDATE() -- true or false FROM mytable WHERE whatever Quote Link to comment https://forums.phpfreaks.com/topic/310254-date-from-timestamp/#findComment-1575388 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.