Hello I am trying to add a 7, 14 or 30 day to our job posting online form. Right know I just have a start and end date drop down. What I have in mind is to do 3 radio buttons with 7 day, 14 day, and 30 day, the I will assing the start day but I want the end date to be calculated automatically deppending on which radio Button was chosen. Is this possible?


Thank you

Recommended Answers

All 5 Replies

<?php //add_days.php
if(isset($_REQUEST['submit'])){
	$start_date="2007-11-25";
	$add_days=$_REQUEST['days'];
	$new_date = date('Y-m-d', strtotime($start_date.' + '.$add_days. ' days'));
	echo $new_date;
}
?>
<html>
<body>
<FORM METHOD=POST ACTION="add_days.php">
<INPUT TYPE="radio" NAME="days" value="7">7<br />
<INPUT TYPE="radio" NAME="days" value="14">14<br />
<INPUT TYPE="radio" NAME="days" value="30">30<br />
<INPUT TYPE="submit" name="submit" value="submit">
</FORM>
</body>
</html>

This will do the work for you.

Cheers.
Nav

This code work the only thing I see a problem is this

$start_date="2007-11-25";

IS there any way to detect the actual day automatically?

Sorry I am new to PHP still learning

Thank you

Joaquiin encinas

The actual day or date ?

Current date :

$today = date('Y-m-d');
echo $today; // This will print for example 2007-11-30

Current day :

$today = date('d');
echo $today; // This will print for example 30

For more options or format -> http://bg2.php.net/date

OK this looks like it will work could you look at this

jobs.yumasun.com/AESgenericII/new_job.php

In the bottom of the formo you will see drop downs for start and end date. above that I will have the radio buttons then after a radio button is selected I will select the start date in the drop down an acording to that a calculation will be made and utomatically wwill set the end date

Ok this work guys very well
I had this to calculate the start date and write it to the db

$s_month = ($_REQUEST);
$s_day = ($_REQUEST);
$s_year = ($_REQUEST);
$start = $s_month . '/' . $s_day . '/' . $s_year;

I used the php scrip that nav33n send and modify it to this

$today = date('m/d/Y');

$add_days=$_REQUEST;

$end = date('m/d/Y', strtotime($start.' + '.$add_days. ' days'));

and it works The start auto selected to actual date but also can be modify and the end date is calculated based on the radio button selection and start date. Very cool

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.