Start New Discussion within our Web Development Community

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


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.


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?

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.

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

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']."'";


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.

yes sir,my code is

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

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

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



        $pdf = new PDF();

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

This question has already been answered. Start a new discussion instead.