Link to home
Start Free TrialLog in
Avatar of woodwyn
woodwynFlag for United States of America

asked on

PHP exporting dates in d-m-year and with an odd default date

Attached is the Reports.PHP file where our data is imported from SQL and exported to a PDF report.  Search for the following block to see where the sub title with the dates in question are being gathered.  FYI, this site was developed by Eastern European developers no longer accessible.  

$text = '';
        foreach($crits as $title => $value) {
            $text .= "<tr><td>&nbsp;&nbsp;$title:&nbsp;&nbsp;$value</td></tr>";
        }
        $html .= "<table style='width:100%; cellspacing='0'> <tr><td><b>Report Criteria</b></td></tr>$text</table><br><br>";

 An example of the output for the above is

Report Criteria
Start Date: 31-12-1969
End Date: 31-12-1969

$title is Start Date: and $value is 31-12-1969

The dates being gathered here are the start and end dates entered in by the user as search criteria.  When displayed in the PDF sub title the dates are displaying as d-m-y, rather than the desired m-d-y and if the search criteria fields are left empty by the user the dates displayed default to and are displayed as 31-12-1969, rather the desired nothing.  Is there a way to modify the way the dates are being displayed to the m-d-y format and to display nothing instead of 31-12-1969 if the users don't enter a search criteria date?

Thanks!!
reports.php
ReportScreenShot.png
SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
31-12-1969 equals a timestamp of 0.  The date formatting code starts with $dStartDate.  The database is probably returning '0' which strtotime() will convert into the minimum datetime of a timestamp which is 1970-01-01 or sometimes 1969-12-31.  To not show that time, you would have to detect the '0' and not let strtotime() convert it to a date.
Avatar of woodwyn

ASKER

Norie - Dropping this block into Reports.PHP generates an error:
Fatal error: Call to undefined function date_create() in E:\Inetpub\nParallel-tst\EOL\application\entity\reports.php on line 259

I don't know much PHP.  Any help you can offer hear would be great.
Avatar of woodwyn

ASKER

I was able to find where the date format was being set to D-M-Y and changed that to M-D-Y.  

I have not resolved the 1969/12/31 default date issue.  I am betting it could be solved in the following block.  Any suggestions?

        $dStartDate =  isset($values['@dStartDate']) ? date('Y-m-d 00:00:01', strtotime($values['@dStartDate'])) : 'GETDATE()';
        $crits['Start Date'] =  date('m-d-Y', strtotime($dStartDate));
        $dEndDate = isset($values['@dEndDate']) ?  date('Y-m-d 23:59:59', strtotime($values['@dEndDate'])) : 'GETDATE()';
        $crits['End Date'] = date('m-d-Y', strtotime($dEndDate));
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial