We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,737 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

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.

6
Contributors
21
Replies
2 Days
Discussion Span
4 Months Ago
Last Updated
22
Views
Question
Answered
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 0

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

@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?

LastMitch
Industrious Poster
4,133 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45

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

diafol
Keep Smiling
Moderator
10,634 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

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

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 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...

NardCake
Posting Whiz in Training
268 posts since Oct 2012
Reputation Points: 20
Solved Threads: 19
Skill Endorsements: 8

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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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.

diafol
Keep Smiling
Moderator
10,634 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

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?

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 0

i am fetching this value from database .

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 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.

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 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?

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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.

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 0

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

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

the mysql query is working right.

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 0

Can you post the whole code.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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(); 
       }
daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 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.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

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

daniel36
Junior Poster
188 posts since Nov 2011
Reputation Points: 5
Solved Threads: 3
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
 
© 2013 DaniWeb® LLC
Page rendered in 0.1330 seconds using 2.78MB