Reputation: 1093
I currently have the following code
$TimelineEvents[$i]["Date"] = date("F j, Y", strtotime($Date));
Which works just fine... Until you want to store a date before Jan 1 1970.
Being that I'm making a timeline, this is rather important functionality. Whats a replacement function I could use?
Thanks Danny
Upvotes: 1
Views: 1539
Reputation: 225044
You could use the DateTime
class instead:
$dateTime = new DateTime($Date);
$TimelineEvents[$i]["Date"] = $dateTime->format('F j, Y');
Upvotes: 5
Reputation:
You should be using the DateTime
class, which will meet your needs:
These functions allow you to get the date and time from the server where your PHP scripts are running. You can use these functions to format the date and time in many different ways.
The date and time information is internally stored as an 64-bit number so all imaginable dates (including negative years) are supported. The range is from about 292 billion years in the past to the same in the future.
Example:
$date = DateTime::createFromFormat("Y-m-d", $Date);
$TimelineEvents[$i]["Date"] = $date->format("F j, Y");
Upvotes: 4