Pergunta

I'm taking two dates from form into mm/dd/yyyy format. Now I'm converting these two dates into equivalent UNIX timestamp value and create a SQL query to fetch the records from the database falling into this range. The small code snippett for this is as given below :

if($request['from_date']!='' && $request['to_date']!='') {
            $from_date  = clean($request['from_date']);
            $to_date    = clean($request['to_date']);       

            list($fd, $fm, $fy) = explode('/', $from_date);
            list($td, $tm, $ty) = explode('/', $to_date);

            $mk_from_time = mktime(0, 0, 0, $fm, $fd, $fy);
            $mk_to_time   = mktime(0, 0, 0, $tm, $td, $ty);
$date_range = " ( user_reg_date BETWEEN ".$mk_from_time." AND ".$mk_to_time." ) ";
}

The properly formatted query gets generated with some other code and gives me the result. But my issue is when I enter two dates viz. 01/07/2013 and 31/07/2013 and fetch the records from DB then it is actually giving the records from date 01/07/2013 to date 30/07/2013. Actually it is expected to give the records till 31/07/2013. If I put to date as 01/08/2013 then it is returning the records till 31/07/2013 as per my requirement. Means in short to date is lagging behind by one day. Can any one help me to resolve this issue? Thanks in advance. One more important thing is the field user_reg_date in DB contains all values in UNIX Timestamp format.

Foi útil?

Solução

Try using

$mk_to_time   = mktime(23, 59, 59, $tm, $td, $ty);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top