Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 11:31 AM

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
<?
$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>


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

<?
$day=date("d");
$month=date("m");
$year=date("y");
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 12:53 PM

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

<option name="day" value="<?echo$day?>">Day <?for($day=1; $day<31; $day++){
echo $day.'<br>';
}?></option>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 May 2006 - 01:07 PM

Try This

<?
$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>


#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 01:24 PM

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

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


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 May 2006 - 01:49 PM

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.
<?
if(isset($_GET['submit'])){
$year = $_GET['year'];
$month = $_GET['month'];
$day = $_GET['day'];
$selected_date = date("Y-m-d", strtotime("$year-$month-$day"));
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:
<?
$day=date("d");
$month=date("m");
$year=date("Y");
?>

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.
<select name="day">
<?
for($days=01;$days<32;$days++){
?>
<option name="day" value="<?=$days?>" <? if($days == $day){ echo "selected";}?>>>Day <?=$days?></option>';
<?
}
?>
</select>[

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.
<? if($years == $year){ echo "selected";}?>>

Hope that helps

Ray

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 May 2006 - 02:04 PM

i need to get the date month and year as one into the database as one field under $date_not_allowed but how cheers, and thank you for your response and explenation cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 May 2006 - 02:13 PM

Just use $selected_date in the example I gave above

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

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

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

Now just insert it into your table

Ray




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users