1,105,625 Community Members

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

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
3
 

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.

LastMitch
Deleted Member
 
0
 

@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
diafol
Where are my eyes?
13,002 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,850 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
2
 

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()

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
NardCake
Posting Pro in Training
417 posts since Oct 2012
Reputation Points: 30 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 9 [?]
 
0
 

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

Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
2
 

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
diafol
Where are my eyes?
13,002 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,850 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
3
 

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.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

i am fetching this value from database .

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
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?

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

the mysql query is working right.

Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

Can you post the whole code.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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(); 
       }
Member Avatar
broj1
Posting Virtuoso
1,580 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 220 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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.

Member Avatar
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: -7 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article