Jump to content

date_create_from_format is breaking on my server and I DON'T KNOW WHY!


Recommended Posts

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?

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.