Can anyone tell me why this outputs a 31?

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
avstudio1
Forum Newbie
Posts: 13
Joined: Mon Nov 07, 2005 5:20 pm

Can anyone tell me why this outputs a 31?

Post by avstudio1 »

I have the following date picker, that I would like for the user to select from a drop box one of past 15 days. Then I want to use only the 'day' component to run some queries on it. For some reason, the result is always a 31, any ideas why?

<form action="Test.php" method="POST">
<select name="PickDate">

Code: Select all

for ($i = 0; $i <= 15; $i++) {
$today = mktime (0,0,0,date("m") ,date("d")-$i ,date("Y"));
$option=date("D M j, Y",$today);
$value=date("m:d:Y",$today);
echo "<option value=\"$value\" $selected>$option</option>\n";
}
<input type=submit>

... and then the POST section in the next page .....

Code: Select all

$PickDay = date("d", $_POST['PickDate']);
echo $PickDay;

.... returns a 31, even though today is the 14th.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

try:

Code: Select all

$PickDay = date("d", strtotime($_POST['PickDate']));
date() expects a unix timestamp as its second parameter, you might have to format the $value a little differently though
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

andre_c wrote:date() expects a unix timestamp as its second parameter, you might have to format the $value a little differently though
Although you could send the value without formatting it at all, ie as a timestamp, to make processing easier.

Mac
avstudio1
Forum Newbie
Posts: 13
Joined: Mon Nov 07, 2005 5:20 pm

Post by avstudio1 »

Thanks.

:)
Post Reply