chrismars Posted January 25, 2011 Share Posted January 25, 2011 Hi, I had an account a while back but lost it lol... need a little help... prob simple but cant figure it... i want to have a user input a date and for php to work out that date 120 days later... thing is i want this to be emailed... basic code so far and it works but cant get it to work with the date maniplation. <?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "my email is here!!!"; $Subject = "DEAL:"; $Deal = Trim(stripslashes($_POST['Deal'])); $Sites = Trim(stripslashes($_POST['Sites'])); $TOS = Trim(stripslashes($_POST['TOS'])); $SST = Trim(stripslashes($_POST['SST'])); $DV = Trim(stripslashes($_POST['DV'])); $DCP = Trim(stripslashes($_POST['DCP'])); $NOTES = Trim(stripslashes($_POST['NOTES'])); $Status = Trim(stripslashes($_POST['Status'])); // validation $validationOK=true; if (Trim($Deal)=="") $validationOK=false; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">"; exit; } // prepare email body text $Body = ""; $Body .= "Deal Done By: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "\n"; $Body .= "Deal Name: "; $Body .= $Deal; $Body .= "\n"; $Body .= "\n"; $Body .= "Number Of Sites: "; $Body .= $Sites; $Body .= "\n"; $Body .= "\n"; $Body .= "Type Of Sale: "; $Body .= $TOS; $Body .= "\n"; $Body .= "\n"; $Body .= "Supplier Signed To: "; $Body .= $SST; $Body .= "\n"; $Body .= "\n"; $Body .= "Deal Value: "; $Body .= $DV; $Body .= "\n"; $Body .= "\n"; $Body .= "Notes: "; $Body .= $NOTES; $Body .= "\n"; $Body .= "\n"; $Body .= "Date Can Be Processed: "; $Body .= $DCP; $Body .= "\n"; $Body .= "\n"; $Body .= $Status; $Body .= "\n"; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=oksub.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/ Share on other sites More sharing options...
AbraCadaver Posted January 25, 2011 Share Posted January 25, 2011 I don't know what format $DCP is in or what format you want the new date in, but here's an example: //convert to unix timestamp $DCP = strtotime($DCP); //add 120 days to timestamp and format it as month-day-year $DCP = date('m-d-Y', strtotime('+120 days', $DCP)); Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165055 Share on other sites More sharing options...
ManiacDan Posted January 25, 2011 Share Posted January 25, 2011 If you're using PHP 5.3, you may also be interested in the date interval class. Also, if you're using stripslashes, you're doing something wrong. Stripslashes is only necessary if you have magic_quotes turned on, and that is widely considered to be bad practice. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165062 Share on other sites More sharing options...
chrismars Posted January 25, 2011 Author Share Posted January 25, 2011 <p>Date Can Be Processed:* <br> <input type="text" name="DCP" class="field" value="<?php echo date("d/m/Y"); ?>" tabindex="7"> above is the input for the user to input the date, its set to a default atm but if the customer inputs their own i want it to give the date +120 in D/M/Y format. im not sure how to get that in to the exisiting code so it outputs in the email sent. Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165073 Share on other sites More sharing options...
AbraCadaver Posted January 25, 2011 Share Posted January 25, 2011 Just what I posted. // PUT IT ANYWHERE AFTER: $DCP = Trim(stripslashes($_POST['DCP'])); // AND BEFORE: // prepare email body text Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165075 Share on other sites More sharing options...
chrismars Posted January 27, 2011 Author Share Posted January 27, 2011 yeah but this does manipulate the date but back to 1970... cant figure out why. Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165908 Share on other sites More sharing options...
ManiacDan Posted January 27, 2011 Share Posted January 27, 2011 January 1, 1970 is "zero time," that's when the Unix epoch began. Any invalid date math comes out to that date. You keep saying you're manipulating the date...but I haven't actually seen any date functions in any of your code. m/d/Y is ambiguous, because europeans use m/d/y. You can switch to a datepicker that returns data in Y-m-d, that may help. Standard debugging steps apply here. Echo what you have. Run strtotime. Echo what that gives you. etc. echo date("Y-m-d", strtotime("1980-03-14") + (60*60*24*120)); //outputs: 1980-07-12 -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1165997 Share on other sites More sharing options...
AbraCadaver Posted January 27, 2011 Share Posted January 27, 2011 Also, as I remember, strtotime() uses the separator to determine what format you are giving. So m/d/y uses the / and d-m-y uses the -. If you mix that up it will be invalid or the wrong date. Quote Link to comment https://forums.phpfreaks.com/topic/225643-php-date-help/#findComment-1166145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.