View Full Version : coding syntax help
grudz
05-02-2005, 09:41 PM
Hi,
I am building a page where a user enters a date (through 3 drop down boxes : month, day, year) into one field (sent), then another field (due) is automatically generated (sent + 30 days)
Now this is what i have so far
$d = $_POST['d'];
$m = $_POST['m'];
$y = $_POST['y'];
$sent = "".$m." ".$d.", ".$y."";
$due = date($sent, strtotime("+30 days"));
but the due date doesnt generate in my database......
Can anybody help me out?
Thank you
marek_mar
05-02-2005, 10:16 PM
Umm... date() doesn't add dates... you should try
strtotime("$y/$m/$d") + strtotime('+30 days')
grudz
05-02-2005, 10:25 PM
If i try that piece of code....and put April 1, 2005 as my sent date, it gives me "1117661194" as my due date?
marek_mar
05-02-2005, 10:33 PM
No wait... you don't want to add the two dates. (why did I think you want to add the date?)
You want the due date output correctly.
<?php
print date('Y M d h:i:s', strtotime('+30 days'));
?>
You can tweak the format. You can read about it on the date() (http://www.php.net/date) functuion page.
grudz
05-02-2005, 10:59 PM
i should make myself a bit more clear...i want to add 30 days to whatever date I use in the dropdown date
$d = $_POST['d'];
$m = $_POST['m'];
$y = $_POST['y'];
$sent = "".$m." ".$d.", ".$y."";
$due = $sent + 30 days;
marek_mar
05-02-2005, 11:19 PM
Oh well then this:
print date('Y M d h:i:s', strtotime("$y/$m/$d") + 60 * 60 * 24 * 30);
grudz
05-03-2005, 12:02 AM
it still gives me June 1, 2005 (30 days after today's date) even if i select April 1, 2005 as the sent date
marek_mar
05-03-2005, 12:45 AM
You know it shouldn't do that... Is the month numeric or named (like January)?
If it's not numeric you could try this:
print date('Y M d h:i:s', strtotime("$d $m $y") + 60 * 60 * 24 * 30);
You could read this fascinating manual about date input formats (http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html) for strtotime() (http://www.php.net/strtotime) if you like.
If it is numeric you could use mktime (which I should have started with... it's 2AM so I can forget stuff)
date('Y M d h:i:s', mktime(0, 0, 0, $m, $d + 30, $y));
this should help you
furture and past dates with php (http://www.dreamweavermxsupport.com/index.php?type=article&id=90&block=1&pid=46&sid=48)
HTH,
vark
grudz
05-03-2005, 01:11 AM
Wow...thanx Marek......
and vark, that seemed pretty logical too....and wouldve worked....thank you both for your time
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.