Jump to content

how to convert the date time stamp into dmy pull down box


redarrow

Recommended Posts

Advance thank you.

I would like a way to get a date month year pull down dox for users to insert the date month and year they select inserted into the database.

but i dont wont to use the old way using <seleect>option metod i wont the same effect but converting the date function.

so that the select statement outputs from todays date month year from 01 to 31 and january to december
and year from 2006 to 2008.



Hope someone has done this and can help cheers.

example but needs help cheers
[code]
<?
$day=date("d");
$month=date("m");
$year=date("y");
?>

<form metod="post" action="">
<select name="day">
<option name="day" value="<?echo$day?>">Day <?echo$day?></option>
</select>
<select name="month">
<option name="month" value="<?echo$month?>">Month <?echo$month?></option>
</select>
<select name="year">
<option name="year" value="<?echo$year?>">Year <?echo$year?></option>
</select>
<br>
<input type="submit" name="submit date">

</form>
[/code]


i am so close.
The above code prints in a select box todays day month year
But i need to alter this code below to get the day from 0-31 month from 0-12 and year from 2006-2008

[code]
<?
$day=date("d");
$month=date("m");
$year=date("y");
?>
[/code]
Link to comment
Share on other sites

I thort that this was correct to get a drop down box from 1-31 but its in a stright line please help cheers.

[code]
<option name="day" value="<?echo$day?>">Day <?for($day=1; $day<31; $day++){
echo $day.'<br>';
}?></option>
[/code]
Link to comment
Share on other sites

Try This

[code]<?
$day=date("d");
$month=date("m");
$year=date("Y");
?>

<form metod="post" action="<?=$_SERVER['PHP_SELF']?>">
<select name="day">
<?
for($days=01;$days<32;$days++){
?>
<option name="day" value="<?=$days?>">Day <?=$days?></option>';
<?
}
?>
</select>
<select name="month">
<?
for ($months=1;$months<13;$months++){
?>
<option name="month" value="<?=$months?>" <? if($months == $month){ echo "selected";} ?>>Month <?=$months?></option>';
<?
}
?>
</select>
<select name="year">
<?
for($years=2006; $years<2010;$years++){
?>
<option name="year" value="<?=$years?>" <? if($years == $year){ echo "selected";}?>>Year <?=$years?></option>
<?
}
?>
</select>
<br>
<input type="submit" name="submit date">
</form>[/code]
Link to comment
Share on other sites

Can you kindly point me in the correct way to get

date
month
year

as one varable to post as as
$date_not_allowed

cheers.

and also if got time exsplain your code in deatail as learning cheers

grate job 10/10

example
[code]

$date_not_allowed=($date && $month && $year);
$date_not_allowed=($_post["date_not_allowed"]);

[/code]
Link to comment
Share on other sites

I'm not sure I get you on the date not allowed thing. Maybe explain a little more what you are trying to do would help. If you are looking to blacklist certain dates, I do not think you will able to do it in the selection part. You will be able to do it after it is submitted though, as long as you have a list or table with the values in it.
[code]<?
if(isset($_GET['submit'])){
$year = $_GET['year'];
$month = $_GET['month'];
$day = $_GET['day'];
$selected_date = date("Y-m-d", strtotime("$year-$month-$day"));[/code]
Now you can just pull a query and compare it against $selected_date

As far as code goes:

This pretty easy, get seperate day, month and year values:
[code]<?
$day=date("d");
$month=date("m");
$year=date("Y");
?>[/code]

This loops through the days, months, and years starting at 1 and going to the desired end, The second parameter in the loop (<) will not give you that value, only what is below it. So when using the loop always use a value one above what you want.
[code]<select name="day">
<?
for($days=01;$days<32;$days++){
?>
<option name="day" value="<?=$days?>" <? if($days == $day){ echo "selected";}?>>>Day <?=$days?></option>';
<?
}
?>
</select>[[/code]

This code is used in all to select the current day, month or year. It basically says if your $years(loop value) is equal to $year(your current day, month or year) then mark that value as the selected one.
[code]<? if($years == $year){ echo "selected";}?>>[/code]

Hope that helps

Ray
Link to comment
Share on other sites

Just use $selected_date in the example I gave above

[code]$year = $_GET['year'];
$month = $_GET['month'];
$day = $_GET['day'];

$date_not_allowed = date("Y-m-d", strtotime("$year-$month-$day"));[/code]

if the date was 01/01/2007 the above example will output 2007-01-01.

Now just insert it into your table

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.