Baabu Posted March 10, 2008 Share Posted March 10, 2008 hi there i have been trying to use date functions for some function it worked but not for the current time or date here is my query i m using query=mysql_query("select * from pls where MONTHNAME(stock_Date)='March' "); it works for this but how should i use it for current date where as the type of stock_Date is DATETIME i want it to select from pls all the entires for todays date how should i do...any help Quote Link to comment https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/ Share on other sites More sharing options...
obsidian Posted March 10, 2008 Share Posted March 10, 2008 Try something like this: <?php $query = mysql_query("SELECT * FROM pls WHERE DATE(stock_Date) = '" . date('Y-m-d') . "'"); ?> The DATE() function around stock_Date might not be needed, but I placed it there because I don't know if your data type is DATE or DATETIME. Quote Link to comment https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/#findComment-488445 Share on other sites More sharing options...
Baabu Posted March 11, 2008 Author Share Posted March 11, 2008 $dt=date('Y-m-d'); $dtd=date('d'); $dtm=date('m'); $query=mysql_query("select * from pls where MONTHDAY(stock_Date) ='$dtd' and MONTHNAME(stock_Date)='$dtm' "); well can anyone tell me that how can i extract the date from stock_Date in the format as the date function does like for $dtd=11 and for $dtm=3 how can i get from stock_Date as its format is also just like $dt Quote Link to comment https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/#findComment-489339 Share on other sites More sharing options...
obsidian Posted March 11, 2008 Share Posted March 11, 2008 If you are using a DATE data type for stock_Date, it is already in the YYYY-MM-DD format by default. If, to be sure, you wrap the column in the DATE() function as I have in my previous post, it will assure that you have it in the YYYY-MM-DD format like your $dt variable. You could even just do it all with MySQL: SELECT * FROM pls WHERE stock_DATE = CURDATE(); Quote Link to comment https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/#findComment-489399 Share on other sites More sharing options...
Baabu Posted March 11, 2008 Author Share Posted March 11, 2008 thx for your help mate i just placed $dt and it worked but when i use the query u told me it does not display anything even if i echo query it is displayed like this select * from pls where stock_Date = CURDATE() where as this is way i m using to echo it echo "select * from pls where stock_Date = CURDATE() "; but if i use echo "select * from pls where stock_Date = $dt "; it displays correctly Regards Baabu Quote Link to comment https://forums.phpfreaks.com/topic/95369-how-to-go-to-current-date/#findComment-489425 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.