I understand there is an issue with php mktime(), 32bit systems, and years <1901 or >2038, however, my question is, does this issue still remain if operating on a 64 bit system?
I used the code mentioned here and determined my host is running a 64bit system.
I am gathering dates from user inputs in the following format:
$m = user selected month (2 digits); $d = user selected day (2 digits); $y = user selected year (4 digits)
Here is the code I am using to convert the input date into a unix timestamp:
$npt_date=mktime(0,0,0,$m,$d,$y);
And the code to then re-display the date in the basic format xx-xx-xxxx
$date_str=date('m-d-Y',$npt_date);
The code works fine for dates > 1901, however, when $y < 1901, the output from the date() function returns the incorrect date.
Any advice as to what I am doing wrong, if this is even possible using the mktime() and date() functions, and/or possible workaround would be greatly appreciated.
Thanks in advance.
Presumably, if you are storing more recent dates, you will never need more than 256 possible year values, which fits exactly into one byte. This saves you significant amounts of space: rather than using multiple bytes to store the integer 1901, 1900 years of which can be considered redundant in many cases, MySQL internally treats it as just the number 1, and displays it at 1901 for your benefit.
If you need more years, use an INT-based type.
also refere this Does MySQL support historical date (like 1200)?
It might be a good idea to start using
DateTime
. It's only limited backwords by the year 1000.Also
time()
anddate()
are limited by 2038 in the future, whereasDateTime
won't have problem with the future either.Here is some reading on the topic.