skeletonjames Posted January 7, 2017 Share Posted January 7, 2017 I recently uploaded my client's site onto a temporary server so that they could get started on data input while I fine tune the design. When I launched it however, one of my sliders and one of my pages broke down completely [note: this only occurs on the server side; my localhost site continues to work perfectly]. I narrowed it down to my use of the date_create_from_format() function as I use it on both pages, and when I remove the element holding that bit of php, the site works fine. I have scoured my file for any missing semi-colons, or brackets, and I can't find any glaring errors. Here is my code as it was orginally on my localhost. <?php $end = date_create_from_format('Ymd',$ending_date); $start = date_create_from_format('Ymd',$starting_date); echo "<span class='month'>" . $start->format('F') . "</span>"; echo " "; echo "<span class='day'>" . $start->format('j') . "</span>"; echo ", "; echo "<span class='year'>" . $start->format('Y') . "</span>"; echo " - "; echo "<span class='month'>" . $end->format('F') . "</span>"; echo " "; echo "<span class='day'>" . $end->format('d') . "</span>"; echo ", "; echo "<span class='year'>" . $end->format('Y') . "</span>"; echo ", $location"; ?> I have also tried converting it from the object to the procedural function (See below) but the result is the exact same. <?php $end = DateTime::createFromFormat('Ymd', $ending_date); $start = DateTime::createFromFormat('Ymd', $starting_date); ?> <?php echo "<span class='month'>" . date_format($start,'F') . "</span>"; echo " "; echo "<span class='day'>" . date_format($start,'j') . "</span>"; echo ", "; echo "<span class='year'>" . date_format($start,'Y') . "</span>"; echo " - "; echo "<span class='month'>" . date_format($end,'F') . "</span>"; echo " "; echo "<span class='day'>" . date_format($end,'d') . "</span>"; echo ", "; echo "<span class='year'>" . date_format($end,'Y') . "</span>"; echo ", $location"; ?> Someone on stackoverflow pointed out that there might be an issue regarding timezone being unidentified, so i made the following modification but the problem persisted. <?php $end = DateTime::createFromFormat('Ymd', $ending_date, new DateTimeZone('America/Toronto')); $start = DateTime::createFromFormat('Ymd', $starting_date, new DateTimeZone('America/Toronto')); ?> Really at a loss here and the deadline is looming. Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/302888-date_create_from_format-is-breaking-on-my-server-and-i-dont-know-why/ Share on other sites More sharing options...
Jacques1 Posted January 7, 2017 Share Posted January 7, 2017 You'll need to be more specific than “the code breaks”. What is the exact error message? If there is none on the screen, check the PHP error log (wherever that is on your server). Also check the inputs: var_dump($ending_date, $starting_date); Are those even valid? Quote Link to comment https://forums.phpfreaks.com/topic/302888-date_create_from_format-is-breaking-on-my-server-and-i-dont-know-why/#findComment-1541144 Share on other sites More sharing options...
Strider64 Posted January 7, 2017 Share Posted January 7, 2017 (edited) Also the standard date format for MySQL is Y-m-d H:i:s not Ymd. That could be part of your problem? Edited January 7, 2017 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/302888-date_create_from_format-is-breaking-on-my-server-and-i-dont-know-why/#findComment-1541148 Share on other sites More sharing options...
maxxd Posted January 9, 2017 Share Posted January 9, 2017 What version of PHP is the staging server using? date_create_from_format() [DateTime::createFromFormat()] was introduced in 5.3.0 according to the docs. Quote Link to comment https://forums.phpfreaks.com/topic/302888-date_create_from_format-is-breaking-on-my-server-and-i-dont-know-why/#findComment-1541230 Share on other sites More sharing options...
requinix Posted January 10, 2017 Share Posted January 10, 2017 Also the standard date format for MySQL is Y-m-d H:i:s not Ymd.Y-m-d is the normal format, but MySQL understands Ymd too. But I don't think MySQL is involved here. Quote Link to comment https://forums.phpfreaks.com/topic/302888-date_create_from_format-is-breaking-on-my-server-and-i-dont-know-why/#findComment-1541237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.