Doing math on mktime

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
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Doing math on mktime

Post by vbmark »

Hello,

I am storing the value of mktime in the endingdate column which is a bigint(20) unsigned field. I can get the value out just fine, but when I do math on it it overwrites. Here's what I'm doing: (using Database.class.php)

Code: Select all

$sql = "SELECT endingdate FROM mytable WHERE id='".$id."'";
$row = $db->query_first($sql);
 
if ($row['endingdate'] != "") {
    $days = 86400 * $days;
    $endingdate += $days;
    $daysinfo['endingdate'] = $endingdate;
    $db->query_update("mytable", $daysinfo, "id='".$id."'");
}
This is driving me nuts :banghead:

I cannot troubleshoot this the normal way because this is in my Paypal ipn return script. So I cannot echo anything to the screen. Any ideas?

Thanks!
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Doing math on mktime

Post by php_east »

is it right to have $daysinfo array in the update field, or should it be $daysinfo['endingdate'] ?
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Re: Doing math on mktime

Post by vbmark »

php_east wrote:is it right to have $daysinfo array in the update field, or should it be $daysinfo['endingdate'] ?
Yes, from the documentation that field takes an "assoc array with data".

Thanks though
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Re: Doing math on mktime

Post by vbmark »

I have simplified the problem even more. Someone has to be able to tell me why this is happening.

Code: Select all

$sql = "SELECT endingdate FROM mytable WHERE id='".$id."'";
$row = $db->query_first($sql);
 
if ($row['endingdate'] != "") {
  echo "endingdate1: ".$row['endingdate']."<br />";
  $endingdate = $endingdate + 1;
  echo "endingdate2: ".$endingdate."<br />";
}
Here are the results:

Code: Select all

endingdate1: 1237694670
endingdate2: 1
Why is endingdate2 echoing 1 when it should be 1237694671?

Thanks!
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Re: Doing math on mktime

Post by vbmark »

Aaaaaaaaaaahhhhhhhhhhh, I GOT IT!!!!

Never mind :crazy:
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Doing math on mktime

Post by php_east »

:wink: string+numeric maybe.
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Re: Doing math on mktime

Post by vbmark »

Nope. The answer is just staring you in the face. Don't feel bad, it took me about 4 hours to figure it out.

It is easier than you think.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Doing math on mktime

Post by php_east »

ah yes, if it was a snake you would have been bitten.
$endingdate = $endingdate + 1;

$endingdate=null :)

i don't feel bad, just curious. things like this catches us all the time, even the seasoned ones.
vbmark
Forum Newbie
Posts: 19
Joined: Sun Feb 15, 2009 8:53 pm

Re: Doing math on mktime

Post by vbmark »

Yup. I just can't believe how much time I wasted on this.

I was googling eveything I could find about mktime.

Oh well. I can get on with my life now. :)
Post Reply