/    Sign up×
Community /Pin to ProfileBookmark

Add days to date using a form

I am creating a database for a game, i want it to look like this one [url]http://dominionagencies.com/warrants/warrantlist.php[/url] where admin enter the number of days, for example person A is aos for 2 days so after 2 days this should not be displayed anymore. I would use a form to enter number of days. But my problem is the php coding, so can anyone help me?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@rodsemSep 27.2011 — Hi 7ood

I used this code for something similar as what you are asking for. In my case I want to show a "NEW" image for stuff loaded in less that 7 days. This is the code:

[CODE]
<?php
// What day is today:
$todayis = strtotime(date('Y-m-d'));

// I define the limite date getting the created date on the DB and adding 7 days
$limitedate= strtotime($row_rsproductos['date_created'], mktime(0,0,0,0,7,0));

// Then I compare the today's date with the limit day and if today is lower than the limit date, then I'll display what I want
if($todayis <= $limitedate) {
?>
<div class="newitemlabel"><img src="images/newlabel.png" /></div>
<?php } ?>
[/CODE]


you can find more information about the "strtotime" function and what it does here: http://php.net/manual/es/function.strtotime.php

I hope it helps somehow! I'm not an advance developer, this works fine for me. I'm sure there must be a better way and surely some of the gurus around here can help us all to get this better, but for a non-advance developer, I think this is simple enough!

Best of luck.
Copy linkTweet thisAlerts:
@jamssmith1Sep 27.2011 — hey bro thnx a lot..i was looking 4 the same..thnx again..


web site designHi 7ood

I used this code for something similar as what you are asking for. In my case I want to show a "NEW" image for stuff loaded in less that 7 days. This is the code:

[CODE]
<?php
// What day is today:
$todayis = strtotime(date('Y-m-d'));

// I define the limite date getting the created date on the DB and adding 7 days
$limitedate= strtotime($row_rsproductos['date_created'], mktime(0,0,0,0,7,0));

// Then I compare the today's date with the limit day and if today is lower than the limit date, then I'll display what I want
if($todayis <= $limitedate) {
?>
<div class="newitemlabel"><img src="images/newlabel.png" /></div>
<?php } ?>
[/CODE]


you can find more information about the "strtotime" function and what it does here: http://php.net/manual/es/function.strtotime.php

I hope it helps somehow! I'm not an advance developer, this works fine for me. I'm sure there must be a better way and surely some of the gurus around here can help us all to get this better, but for a non-advance developer, I think this is simple enough!

Best of luck.[/QUOTE]
Copy linkTweet thisAlerts:
@eval_BadCode_Sep 27.2011 — You could try the jqueryUI's datepicker (javascript). But it's an incredible amount of code for just picking a date... I would avoid using it unless you're already very invested in jqueryUI (I use it all over the place, even wrote a library in PHP for it). ?

If you're interested the PHP code looks like this:

[code=php]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Date Picker</title>
<link type="text/css" href="css/dot-luv/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
</head>
<!-- <?php
#errors are in the comments, also, the browser can begin
#processing the jquery scripts while the server is processing the PHP
function __autoload($class_name) {
require_once('./classes/' . $class_name . '.php');
} //normally this is also auto prepended... just making sure you know how the classes are loaded


$dateInput = UiWidget::getWidget("datepicker");
$dateInput->setOption('dateFormat', "'yy-mm-dd'");

?> -->
<body>
<div>
<?php echo $dateInput; ?>
<script>
$('#<?php echo $dateInput->ID() ?>').attr('name','dateInput');
</script>
</div>
</body>
</html>
[/code]


OUTPUT:
[code=html]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Date Picker</title>
<link type="text/css" href="css/dot-luv/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
</head>
<!-- -->
<body>
<div>
<script>
$(function() {
$( "#w4e821f4232d0b" ).datepicker({dateFormat: 'yy-mm-dd',});

});
</script><input type="text" id="w4e821f4232d0b" /><script>
$('#w4e821f4232d0b').attr('name','dateInput');

</script>
</div>
</body>
</html>
[/code]


Picture:

http://img263.imageshack.us/img263/3639/screenshot1ah.png

I can share the source if you want. It handles the special JqueryUI widgets and also have an exceptional base class (which handled datepicker perfectly fine!) for all other widgets. I added a class for Tabs since the original author did not add one (and the base class did not handle it).

Edit: It looks like a LOT of code for a simply jquery widget. However, the classes allow you to nest things very very well, so you can create amazingly complex sets of widgets that would take hours and hours to do by hand.
Copy linkTweet thisAlerts:
@7oodauthorSep 27.2011 — Thanks guys but you still didn't give me what i want ?, i am somehow new at php so i would want user to enter the date in the text field and then that number of days that the user entered is added to the current date, thats my problem, i don't want to write the number of days in the code i want to take it from users through a form thanks again!
Copy linkTweet thisAlerts:
@eval_BadCode_Sep 27.2011 — [code=php]
This many days: <?php echo date("Y-m-d", isset($_POST['daysPlus']) ? ((INT) $_POST['daysPlus']) * 86400 + time() : time()); ?>
<form method="post" target="self">
<br />
<input type="text" value="" name="daysPlus" />
<button type="submit" />
</form>
[/code]
Copy linkTweet thisAlerts:
@7oodauthorSep 28.2011 — Wooow! Thanks so much Eval, i modified your code so that i can add it to my database instead of echoing ? Thanks again.
×

Success!

Help @7ood 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.17,
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,
)...