Jump to content

how to display data for current month..?


Suthesan

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/274713-how-to-display-data-for-current-month/
Share on other sites

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.