Jump to content

Date problem


Toolmaster

Recommended Posts

Hi guys new to the forum, glad to be here among all you PHP experts!  ;D

Anyway I have a problem in php, I have three drop down list boxes for users to select a day/month they want.

 

<?php
/* Program name: dateSelect.php
* Description: Program displays a selection list that
* customers can use to select a date.
*/
echo "<html>
<head><title>Select a date</title></head>
<body>";
/* create an array of months*/
$monthName = array(1=> "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December");
$today = time(); //stores today’s date
$f_today = date("M-d-Y",$today); //formats today’s date
echo "<div align=’center’>\n";

/* display today’s date */
echo "<p> <h3>Today is $f_today</h3><hr>\n";

/* create form containing date selection list */
echo "<form action=’processform.php’ method=’POST’>\n";
/* build selection list for the month */
$todayMO = date("m",$today); //get the month from $today
echo "<select name=’dateMO’>\n";
for ($n=1;$n<=12;$n++)
{
echo "<option value=$n\n";
if ($todayMO == $n)
{echo " selected";
}
echo "> $monthName[$n]\n";
}
echo "</select>";
/* build selection list for the day */
$todayDay= date("d",$today); //get the day from $today
echo "<select name=’dateDay’>\n";
for ($n=1;$n<=31;$n++)
{
echo " <option value=$n";
if ($todayDay == $n )
{
echo " selected";
}
echo "> $n\n";
}
echo "</select>\n";
/* build selection list for the year */
$startYr = date("Y", $today); //get the year from $today
echo "<select name=’dateYr’>\n";
for ($n=$startYr;$n<=$startYr+3;$n++)
{
echo " <option value=$n";
if ($startYr == $n )
{
echo " selected";
}
echo "> $n\n";
}
echo "</select>\n";
echo "</form>\n";
?>

(code obtained from PHP and MYSQL for Dummies)

 

I have created an array to insert all the months of the year, and I have stored today's date on there so that each day it changes every 24hours. I would like to get help with a formula that would enable the user to only select the current date and any remaining days after in one particular month. So for example, today is the 23rd March, so I will be able to select 23rd or up to 31st March (31 days in March), but no date before 23rd. If a user selects another month, so instead of March they choose April, then the days that will appear will be dependant on how many days there are in April. (30 days in April).

 

Anyone of you smart intellectuals got any ideas?

Link to comment
https://forums.phpfreaks.com/topic/43926-date-problem/
Share on other sites

Is there a way to do it without using such an array? I mean it is all well and good as it looks to be the easy way of doing it, but is there a way that it can be done so that I won't need to keep changing the day numbers every year?

 

Thanks for your help look forward to reading your response

 

Tim

Link to comment
https://forums.phpfreaks.com/topic/43926-date-problem/#findComment-213380
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.