dear friends
m using strtotime () function to compare two dates , but it is not working for the date greater then '19-jan-2038'.my os is win 7 32 bit and php 5.2 and apache 2.2.plz if any body having any solution , kindly share it
dear friends
m using strtotime () function to compare two dates , but it is not working for the date greater then '19-jan-2038'.my os is win 7 32 bit and php 5.2 and apache 2.2.plz if any body having any solution , kindly share it
Short answer: the root cause is the 32‑bit Unix timestamp limit (the “Year‑2038” problem). Using PHP DateTime objects (created from date strings) and comparing DateTime objects avoids the timestamp overflow — but avoid any code that converts back to a 32‑bit Unix timestamp (strtotime(), time(), mktime(), DateTime::getTimestamp() / format('U')) on a 32‑bit PHP build. (en.wikipedia.org)
Practical approach (build on ’s suggestion): always create DateTime objects from strings and compare those objects directly instead of converting to integers. Example pattern (different from the snippet already posted in the thread):
$left = DateTime::createFromFormat('Y-m-d', '2045-06-10');
$right = DateTime::createFromFormat('Y-m-d', '2050-01-01');
if ($left < $right) {
echo $left->format('Y-m-d') . " is before " . $right->format('Y-m-d');
} Don’t call getTimestamp() or format('U') on a 32‑bit PHP build for dates beyond 2038 — those will fail or return false. Using DateTime methods (format other than 'U', diff(), direct comparison) gives reliable results. (ourcodeworld.com)
Troubleshooting checklist (what can try now)
echo PHP_INT_SIZE; — 4 = 32‑bit, 8 = 64‑bit. If you’re on 32‑bit, strtotime()/time()/mktime will hit the limit. (learn.microsoft.com) Short plan: switch comparisons to DateTime objects created from ISO strings, avoid Unix‑timestamp conversions on 32‑bit PHP, or move to 64‑bit PHP / use DATETIME in DB. This follows and ’s diagnosis but gives the concrete workaround and checks to use immediately.
Jump to Post— ehpratah 48your script pls?
Jump to Post— Member #120589Use
DateTime()as this does not use internal integers and gets around the 32-bit issue.
This is the best way strtotime() works for me. A string like so '05/23/2014' in a mm/dd/yyyy format converts to 1400821200 in time and the datatype should be int. To convert back to date format, you can do date('d-m-Y',1400821200)
your script pls?
Use DateTime() as this does not use internal integers and gets around the 32-bit issue.
The maximum value of a 32-bit integer is 2,147,483,647. 2,147,483,647 seconds from 01-01-1970 00:00:00 is January 19, 2038. If you add one more second, you get a date somewhere in 1902... so, your answer would by what @diafol said
dear friends i got maximum solution from DateTime() function here is some helpful links
1.Click Here
2.Click Here
3.Click Here
4.Click Here
but i am still facing problem to retrive current date ( which is after '19-jan-2038') by datetime function. my code is as follows:
<?php
$date= new datetime();
echo $date->format('d-m-Y');
?>
diafol sir plz give any solution
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.