Forum Moderators: coopster

Message Too Old, No Replies

month year

         

swati

1:24 pm on Oct 27, 2004 (gmt 0)

10+ Year Member



Hello,
I am providing a drop down list to the user with values such as
Oct-2004
Nov-2004
Dec-2004
n so on
if the user selects nov-2004 the month november n year 2004 should get stored in my MySQL database.(precisely which data type should i use to efficiently store month as well as year?)

However if the current month is november the drop-down should not contain options such as october or september. How do I do this?

Also is there a better way to handle this issue? Please advise me as I dont know the best way to go about this matter.
Regards
Swati

jatar_k

6:05 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I use DATE, DATETIME and even VARCHAR it depends partially on personal preference and also what you plan on doing with it.

column definitions and formats
[dev.mysql.com...]

the dates can also just be stored as strings which works fairly well. I try to store either YYYY-MM-DD, YYYY-MM-DD HH:MM:SS (if I need time) or just use unix timestamps which makes comparison and formatting as starightforward as possible.

if you were using unix timestamps, functions such as

$selectyear = strftime [php.net](%b-%Y,$timestamp);

would change the format of your saved value into the format you are using

>> if the current month is november the drop-down should not contain options such as october or september

what should it contain then?

thing is there are 2 portions to your question, you first need to decide what format will make it easiest for you to do all of the math/display you will need to do on your dates. Once you have figured that out it is simple to choose the best format to store it in.

Once you have decided on functionality and format you can then decide how the value needs to be formatted in your drop down and what functions to use to convert back end dates for math into displayable versions.

Start with the db date format decision then worry about how you are going to display it.

I figure for your dropdown

use date() [php.net] to get the current month and year
Build your drop down based on those values
insert it in any format you want

swati

1:19 pm on Oct 28, 2004 (gmt 0)

10+ Year Member




i have created an array containing values like Nov-2004 so on and put them into the drop-down.
If current month is october then the drop down should contain values for next 6 months.
It should not contain values like September or august.
User should be able to select coming months only.
For this the values wud have to be dynamically generated depending on the current month.
no clue on how to do that
please help!

jatar_k

4:31 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think I get it, I can at least show you how to build the drop down

<form name="monthtest"> 
<select name="month">
<?
$today = time();
for ($i=1;$i<=6;$i++) {?><?
$today = strtotime("+1 month",$today);
$nextmonth = strftime("%b-%y",$today);
echo "<option value=\"$nextmonth\"";
echo ">" . $nextmonth . "</option>";
}
?>
</select>
</form>