Displaying date 1970-01-01 instead of desired date. my code is

date('Y-m-d',$rtTransaction->getAddedOn());

the date returned by the function is in format '1353658977',Please help me. Thank you.

1353658977 seem to be date in unix timestamp which converts to Fri, 23 Nov 2012 08:22:57 GMT. If you get 1970-01-01 something must be wrong since the unix timestamp for this date is 0. If $rtTransaction->getAddedOn() returns timestamp then it ovbiously returns 0.

Member Avatar for LastMitch

@daniel36

Displaying date 1970-01-01 instead of right date.

I find it odd that you want to change the display date on an transaction that is 23 years ago. May I ask why you need to change the date that far back?

Member Avatar for diafol

The second parameter in date() must be an integer greater or equal to 0. NULL, false, 0 and negative numbers will give 1970-01-01. Strings will give an error. So, you need to investigate the return value for the method $rtTransaction->getAddedOn()

i did not get proper answer,how can i fix the problem to get correct date from code?

I don't understand what you are trying to do. If you just need to display a specific date just echo it out as a string...

To restate the above answers: the method $rtTransaction->getAddedOn() presumably returns a unix timestamp which you want to convert to human readable date. If the displayed date is 1970-01-01 then the $rtTransaction->getAddedOn() method has returned 0 which is a timestamp that translates to 1970-01-01. As said above: investigate the $rtTransaction->getAddedOn() since the error is quite possibly there. You can also post the method here.

Member Avatar for diafol

i did not get proper answer

Yes you did.

how can i fix the problem to get correct date from code?

Read posts by broj1 and myself. We do not have a crystal ball to know which value your method is returning.

Yes sir you are right ,i have changed upper code with date("Y-m-d",$vrow['added_on']) ,but the $vrow['added_on'] is reruning 0.i am unable to understand why is it?

i am fetching this value from database .

I am unable to fetch the value in database in 'added_on' column.other values are previewing correctly.but this is showing only 0.

What is the query that reads the values from the database? Does the value exist in the added_on column? Does any data for the query come from a form?

my query is-

$vquery="SELECT * FROM rt_transaction WHERE added_on>=Unix_Timestamp(".$date1.") AND added_on<=Unix_Timestamp(".$date2.") AND rt_owner_id='".$_POST['owner']."'";

in which date1 and date2 are coming from the form.and also added_on column having the value.thank you for your response.

the date is in format-yyyy-mm-dd.

Do you do any checking on dates that come from the form i.e. are the dates in correct format or is date2 >= date1 etc? I suggest you put the debug code just after the SQL statement:

$vquery="SELECT * FROM rt_transaction WHERE added_on>=Unix_Timestamp(".$date1.") AND added_on<=Unix_Timestamp(".$date2.") AND rt_owner_id='".$_POST['owner']."'";

// DEBUG
die($vquery);

This code will display the query and stop the script. Please test the displayed query in phpmyadmin or mysql client (assuming you use mysql) or post it here.

the mysql query is working right.

Can you post the whole code.

yes sir,my code is

IF(isset($_POST['view_all_report']) || isset($_POST['view_owner_report']))
          {
        //$columnWidthList=array(20,40,25,16,40,20,25);
          $columnWidthList=array(20,40,52,25,25,25);
        //$headerList=array('Txn Id', 'Txn Date', 'Amount', 'Type','Payment Method','Status','Balance');
          $headerList=array('Txn Date', 'Txn Unit', 'Description','Income','Expend','Balance');


  IF(isset($_POST['view_all_report']))
      {
         $date1=$_POST['from'];
         $date2=$_POST['to'];
         $vquery="SELECT * FROM rt_transaction WHERE added_on>=Unix_Timestamp('".$date1."') AND added_on<=Unix_Timestamp('".$date2."')";
         $vresult=mysql_query($vquery) or die(mysql_error());
         die($vquery);

        $dataList=array();
        while ($vrow=mysql_fetch_assoc($vresult))
             { 
        $wquery="SELECT rt_user_name FROM rt_user WHERE rt_user_id='".$vrow['rt_owner_id']."'";
        $wresult=mysql_query($wquery) or die(mysql_error());

       while($wrow=mysql_fetch_assoc($wresult))
              {
                 $txnunit=$wrow['rt_user_name'];
              }  

        IF($vrow['rt_txn_type']=='C')
           {
             $income=$vrow['rt_txn_amount'];
             $spend=0;
             $balance=$vrow['rt_txn_amount'];
           }
         else
          {
             $income=0;
             $spend=$vrow['rt_txn_amount'];
             $balance="-".$vrow['rt_txn_amount'];
          }
        $dataList[]=array(
                                //$rtTransaction->getRtTxnId(),
                                date("Y-m-d",$vrow['added_on']),
                                $txnunit,
                                $vrow['rt_txn_desc'],
                                $income,
                                $spend,
                                $balance
                            );
        }

        $pdf = new PDF();
        $pdf->setDataList($dataList);
        $pdf->setHeaderList($headerList);
        $pdf->setColumnWidthList($columnWidthList);
        $pdf->SetFont('Arial','',9);
        $pdf->SetRightMargin(5);
        $pdf->AddPage();
        $pdf->generateBasicTable();
        $pdf->Output(); 
       }

Can you comment out the die statement on line 16 and insert this debug code after line 20 (in the beginning of the while loop):

if($vrow['added_on'] <= 0) {

    die($vrow, 1));
}

This will output the value of the $vrow in a case where $vrow['added_on'] equals 0 or less than 0. You have to investigate that row then. Please post the result here if you do not manage to debug the error yourself.

This is not working .giving error
Parse error: syntax error, unexpected ',' in /opt/lampp/htdocs/rent/admin/rttransaction.php on line 200

Line 3 above should be:

die($vrow);

sir i have solved this.I removed the where clause and use conditions later.very very thank you for your response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.