Asked  7 Months ago    Answers:  5   Viewed   42 times

I am using PHP and jQuery to build an interactive timeline which needs to display dates between 1500 and 2020. I usually use PHP's strtotime function when working with dates, but it does not work for dates pre-1900.

The dates will come from a MySQL database, and are formatted as strings such as "January 31, 1654" (this may not be the ideal format, but I can't change how they are stored). I am using PHP to parse the dates, basically converting them into pixel values which determine where they are displayed on the timeline.

What is the easiest way to parse these historical dates?



The DateTime class, here, might help (quoting):

Each component of date (e.g. year) is internally stored as 64-bit number so all imaginable dates (including negative years) are supported.

But note that:

  • It's only exists in PHP >= 5.2
  • And several methods only exist in PHP >= 5.3

So: beware of which methods you're using, if you're developping on PHP 5.3 and want your software to be compatible with PHP 5.2

Another solution (especially, if using Zend Framework in your application) would be the Zend_Date component (quoting):

Although PHP 5.2 docs state, "The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT," Zend_Date supports a nearly unlimited range, with the help of the BCMath extension

Wednesday, March 31, 2021
answered 7 Months ago

mktime() - Get Unix timestamp for a date

echo mktime(23, 24, 0, 11, 3, 2009);

To handle AM/PM just add 12 to hours if PM.

mktime($isAM ? $hrs : ($hrs + 12), $mins, $secs, $m, $d, $y);

Alternatively you could use strtotime():

strtotime() - Parse about any English textual datetime description into a Unix timestamp

echo strtotime("2009-11-03 11:24:00PM"); 
Wednesday, March 31, 2021
answered 7 Months ago

{Edit} removed old reference link

Seconds since Jan 1, 1970 = unix time

To get this in VB.NET see below example (in example using DateTime.UtcNow, but you can plug in any DateTime you want there)

Dim uTime As Double
uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
Thursday, July 29, 2021
answered 3 Months ago

Check out the GNU Multiple Precision and BC Math extensions.

Friday, August 6, 2021
answered 3 Months ago

This isn't really the job of phpMyAdmin, a GUI for MySQL beginners.

Put the query in a script, in a loop that runs 1,000,000 times.

Though that's not a very good benchmark of anything. If you're trying to simulate real demand, you need to have some concurrent activity, not just 1,000,000 queries issued and returned one at a time.

Saturday, August 28, 2021
Giorgi Peikrishvili
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :