Grow your CSS skills. Land your dream job.

Date is outputting two days

  • # August 21, 2012 at 2:25 pm
    $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

    # August 21, 2012 at 3:06 pm

    You’ll need to post more code… looks like you’re echoing out in a loop of some kind.

    # August 21, 2012 at 3:15 pm

    I am sending two emails on one file.


    < ?php

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

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "";
    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));
    $Email = Trim(stripslashes($_POST));
    $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 "";
    }
    else{
    print "";
    }
    ?>
    # August 21, 2012 at 4:07 pm

    ??
    Its right there in the code you posted – two ‘d’ (each two digit date).

    $date = date('M dd Y'); 
    # August 21, 2012 at 4:09 pm

    If I put one d it still outputs two days. Here are the results below…

    d 2121
    DD TueTue
    D Tue
    dd 2121

    # August 22, 2012 at 10:31 pm

    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).

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".