Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
Oren wrote:I run PHP 5.1.4 and when I entered a date before 1.1.1970 the function returned 36, so I guess the negative timestamps don't work after all.
I run PHP 5.1.2 and it works well with dates upto 1901. It seems to screw up with 1900 though and I can't figure out why.
Note: 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. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.
I have PHP 5.1.2 on Windows XP Professional running Apache 1.3 and negative timestamps work for me upto 13 Dec 1901 [/url]
Note: 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. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.
I have PHP 5.1.2 on Windows XP Professional running Apache 1.3 and negative timestamps work for me upto 13 Dec 1901
That's strange, dates before 1.1.1970 shouldn't work on a windows system.
Verminox wrote:Well unless somebody has secrectly installed a Linux distribution on my machine and made it look like WinXP I think it should work, actually.
And it says on php.net that the issues was fixed after PHP 5.1.0, so there we go.
I don't know, it didn't work for me and I run PHP 5.1.4
d11wtq wrote:~Verminox is your system 32 bit or 64 bit?
32-Bit
I can copy my phpinfo() page somewhere else and show you if you want to know know the configuration settings.
I have no clue how it is working on my machine o_O
Edit: Oren, you said you tried a date before 1.1.190. Did you try 1969 because then it would return 36 even after taking a negative timestamp which you might have overseen. Try with a date such as "1 Jan 1940" and check if it returns 66.
Something very strange is going on here... I had tested my function again and for 1.1.1960 it gave me 36 and for 1.1.1940 it gave me 0.
I then ran another test and all of a sudden it worked even with dates like 1.1.1902.
This is very strange, anyone has any ideas?
Oren wrote:Something very strange is going on here... I had tested my function again and for 1.1.1960 it gave me 36 and for 1.1.1940 it gave me 0.
I then ran another test and all of a sudden it worked even with dates like 1.1.1902.
This is very strange, anyone has any ideas?
Are you using the same function you posted earlier?
5 => A unix timestamp cannot be made for a date prior to 13 Dec 1901 since it is the maximum negative value a 32-bit signed integer can take. Hence, the strtotime() function returns 0 which makes the age 36 (counting the DOB to be 1.1.1970).
6 => Works as expected
7 => Same as (5), but this time the max value in the postive side.
Doesn't look like a problem to me on WinXP Professional/Apache 1.3/PHP 5.1.2
I like AKAPJ's. I think relying on a timestamp that, for the time being, is limited to essentially last century through the first 40 years of this century is kinda wonky. There will be some big trouble when it comes to the actual format of the date passed to the function (as in, we Americans do it one way and the rest of the world does it a bit different), but I rather like the tought of subtracting the date in parts to arrive at an age.
I have a question for this code is this the right bdate code?
because i tried these code and isn't working i mean it does but my age is 22. on that code it show my age is 23.