Page 1 of 1

Can anyone tell me why this outputs a 31?

Posted: Wed Dec 14, 2005 3:40 pm
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.

Posted: Wed Dec 14, 2005 3:52 pm
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

Posted: Thu Dec 15, 2005 3:33 am
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

Posted: Fri Dec 16, 2005 7:58 am
by avstudio1
Thanks.

:)