Why won't PHP do a simple addition problem? (2+1=21)?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

Why won't PHP do a simple addition problem? (2+1=21)?

Postby Tony121076 » Thu Feb 20, 2003 12:39 pm

The following lines of code all produce 21 instead of 3, why? I understand whats it's doing, but how can you do addition problems?

-------------------------
$mo = intval(date("j"));
$mo = ++$mo;
returns 21
-------------------------
$mo = date("j") + 1;
returns 21
-------------------------
$mo = intval(date("j")) + 1;
returns 21

*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Postby *JaH* » Thu Feb 20, 2003 3:16 pm

dude, it is the 20th of february...not the 2nd :D (so 20+1=21)

User avatar
gorshing
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Dec 05, 2002 5:56 pm
Location: Oklahoma, US
Contact:

Postby gorshing » Fri Feb 21, 2003 7:20 am

Were you confused on the date function? He could had thought that it would return the month and not the day of the month.

http://www.php.net/manual/en/function.date.php

passing 'j' gives you the day of the month.

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

oops :)

Postby Tony121076 » Fri Feb 21, 2003 11:21 am

oops. Thank you. I thought j was the month. :) I can't believe something so simple cost me so much time.

*JaH*
New php-forum User
New php-forum User
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Postby *JaH* » Fri Feb 21, 2003 5:36 pm

yeah those things are a bitch :D ...it's always the small things that takes loads of time to make it right :)


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron