treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Date is outputting two days

  • $date = date('M d Y'); 


    Why am I getting two days?
    ----> Aug 2121 2012

    These are the results I am getting on the right side below...
    d 2121
    DD TueTue
    D Tue
    dd 2121

    I just want one day like Aug 21 2012 or Aug 21st 2012
  • You'll need to post more code... looks like you're echoing out in a loop of some kind.
  • I am sending two emails on one file.


    <?php

    $EmailFrom = "TEST";
    $EmailTo = "XXX@gmail.com";
    $Subject = "Contact Us";
    $Name = Trim(stripslashes($_POST['Name']));
    $Phone = Trim(stripslashes($_POST['Phone']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Phone: ";
    $Body .= $Phone;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    ?>



    <?php

    // CHANGE THE VARIABLES BELOW

    $EmailFrom = "TESTTHANK";
    $Subject = "Thank You";
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $date = date('M dd Y');

    // prepare email body text


    $Body = "";
    $Body .= $date."\n";
    $Body .= "\n";
    $Body .= "\n";
    $Body .= $Name . ":";
    $Body .= "\n";
    $Body .= '
    I am delighted you contacted us.
    ';

    // send email
    $success = mail($Email, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.XXX.com\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
  • ??
    Its right there in the code you posted - two 'd' (each two digit date).
    $date = date('M dd Y'); 
  • If I put one d it still outputs two days. Here are the results below...

    d 2121
    DD TueTue
    D Tue
    dd 2121
  • double-check.
    M d Y will result in (something like) "August 22 2012", whereas M dd Y will result in "August 2222 2012".

    Running the actual code you posted ("as-is," and corrected) produces these results as expected (yes, I tested it).