Time Stamp Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Time Stamp Issue

Post by JakeJ »

I'm using a function that returns a future date. In some cases, the date goes beyond 19 Jan 2038 03:14:07 UTC. which is the upper limit for a 32 bit signed integer.

Anyone have a custom function that can some how get around this limit?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Time Stamp Issue

Post by requinix »

Depends what you're doing with it. Post some code.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Time Stamp Issue

Post by JakeJ »

Here's a function I wrote to return a future date based on a number of months from now. My temp fix should be obvious.

Code: Select all

function ffdate($months) {
    If ($months < 335) { #REMOVE THIS IF BEFORE MOVING TO 64 BIT HOSTING
    return date('F, Y ', strtotime("+ {$months} months"));
    }
    Else {
    return "Beyond 2037";
    }
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Time Stamp Issue

Post by requinix »

You can always calculate the date manually.

Code: Select all

month = M
year = Y
monthstoadd = X
 
new month = (M + X - 1) mod 12 + 1
new year = Y + floor(X / 12)
if (new month > 12) {
    new month -= 12
    new year++
}
Post Reply