/    Sign up×
Community /Pin to ProfileBookmark

[b]now i have this form and i want to get todaysdate in the text box named today_date

after that i want the user to enter a date in entered_date and i want to compare this date with today_date and show the answer

i dont know how to make it using php

i need a full help wiz code can anyone helps me??

[/b]

<table width=”600″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<form id=”1″ name=”1″ method=”get” action=”test1″>
<tr>
<td width=”40%”><label for=”today_date”>Today Date <br>
<span class=”style1″>( Date format is dd-mm-yyyy)</span></label></td>
<td width=”20%” align=”center” valign=”middle”>&nbsp;</td>
<td width=”50%”><input type=”text” name=”today_date” id=”today_date” readonly onblur=”return datediff();” /></td>
</tr>
<tr>
<td><label for=”entered_date”>Entered Date<br>
<span class=”style1″>( Date format is dd-mm-yyyy)</span></label></td>
<td align=”center” valign=”middle”>&nbsp;</td>
<td><input type=”text” name=”entered_date” id=”entered_date” onblur=”return datediff();”/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Date Difference</td>
<td>&nbsp;</td>
<td><label for=”difference”></label>
<input type=”text” name=”difference” id=”difference” readonly /></td>
</tr>
</form>
</table>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bejitto101Dec 11.2008 — Well it almost looks to me like you want this to be done with JS because of that onblur but here's how you would do it with PHP. This all would be done in "action" page of the form.

I do suggest you ask in the javascript forum however.

[code=php]

$date1 = strtotime($_GET['entered_date']);
$date2 = strtotime($_GET['today_date']);

$dateDiff = $date1 - $date2;
$fullDays = floor($dateDiff/(60*60*24));
$fullHours = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
echo "Differernce is $fullDays days, $fullHours hours and $fullMinutes minutes.";
[/code]


Edit: For an example of what I think you want check here: http://javascript.internet.com/math-related/date-difference.html
Copy linkTweet thisAlerts:
@SodbusterDec 11.2008 — You can also do it like this with PHP:[code=php]function date_time_diff($start, $end, $date_only = true) // $start and $end as timestamps
{
if ($start < $end) {
list($end, $start) = array($start, $end);
}
$result = array('years' => 0, 'months' => 0, 'days' => 0);
if (!$date_only) {
$result = array_merge($result, array('hours' => 0, 'minutes' => 0, 'seconds' => 0));
}
foreach ($result as $period => $value) {
while (($start = strtotime('-1 ' . $period, $start)) >= $end) {
$result[$period]++;
}
$start = strtotime('+1 ' . $period, $start);
}
return $result;
}

$date_1 = strtotime('2005-07-31');
$date_2 = time();
$diff = date_time_diff($date_1, $date_2);
foreach ($diff as $key => $val) {
echo $val . ' ' . $key . ' ';
}

// Displays:
// 3 years 4 months 11 days[/code]
×

Success!

Help @john_zakaria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...