Suthesan Posted February 20, 2013 Share Posted February 20, 2013 now below code call data from db by 1-31 jan.. how if i want replace this code..calling data for current month? PLS help! <?php $cmonth = date(m); $cyear = date(y); $cart = "select * from tbl_cart where pdate between '2013-01-01' and '2013-01-31' and uid = '".$_SESSION['id']."'"; $rscart = $obj->select($cart); ?> bpr.inc.php Quote Link to comment https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/ Share on other sites More sharing options...
requinix Posted February 20, 2013 Share Posted February 20, 2013 Use mktime() and date() to get the beginning and end of the month. Tip: for mktime(), use day=0 of the next month to get the last day of the current month. Or use MySQL's DATE() function. Quote Link to comment https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/#findComment-1413578 Share on other sites More sharing options...
codebyren Posted February 20, 2013 Share Posted February 20, 2013 You can get the first and last day of the current month pretty easily using the date() function. Something like: <?php $first_day = date('Y-m-\0\1'); # force "01" as the day here. $last_day = date('Y-m-t'); # the "t" is for the number of days in the given month (i.e. always the last day of the month) $cart = "select * from tbl_cart where pdate between '$first_day' and '$last_day' and uid = '".$_SESSION['id']."'"; ?> Hope I didn't overlook anything... Quote Link to comment https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/#findComment-1413579 Share on other sites More sharing options...
Suthesan Posted February 20, 2013 Author Share Posted February 20, 2013 Mr behicthebuilder, thanks for your reply..i appreciate it..but..its not working got any other way? Mr requinix : can give me full code? Quote Link to comment https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/#findComment-1413584 Share on other sites More sharing options...
Suthesan Posted February 20, 2013 Author Share Posted February 20, 2013 Mr behicthebuilder, Thanks..its working..thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/#findComment-1413585 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.