Any PHP Coders Can Help Please?

5 replies
Alright guys

I have create one text box with the name product_date which uses alongside it a datepicker to choose the date. The format of the date entered into that text box is mm-dd-yyyyy.

Which of course when you try and stored into a msql db field with the date value.. It will not work! The defualt format for it is yyyy-mm-dd

I have used the following peice of code:
$product_date = date("Y-m-d", strtotime($_POST["product_date"]));

Which allows me to be able to enter the date in the right format into the db field..

I am now wanting to change how it is displayed.. Please see here Untitled Document At the moment it is displayed in the yyyy-mm-dd format..

I need some php code written that allows me to take the information from the product_date field and the output in mm-dd-yyyy

Can anyone help me through this process please??
#coders #php
  • Profile picture of the author fthomas137
    I truly hear your pain. I've struggled with mysql and php on several occasions because of date stamping.

    When you want to output the day in the proper format you can do the following:

    echo date('m-d-Y',strtotime($theMySQLPulledDate));

    Use the following page as a template to what you are trying to do:

    PHP: date - Manual

    Cheers!

    Frank
    {{ DiscussionBoard.errors[1712530].message }}
    • Profile picture of the author Byron_Wells
      Originally Posted by fthomas137 View Post

      I truly hear your pain. I've struggled with mysql and php on several occasions because of date stamping.

      When you want to output the day in the proper format you can do the following:

      echo date('m-d-Y',strtotime());

      Use the following page as a template to what you are trying to do:

      PHP: date - Manual

      Cheers!

      Frank
      Alright Frank

      Can you just confirm this for us please...

      At the moment I have the above code supplied on the add_products page.. I do also have this bit of code on the same page..

      $set .= "product_date = '$product_date'";

      Then on the marketplace.php page see here Untitled Document

      This code used I beleive to get the information from the db filed?
      $product_date = $r[product_date];

      I am correct? or confused??
      {{ DiscussionBoard.errors[1713659].message }}
      • Profile picture of the author fthomas137
        Originally Posted by Byron_Wells View Post

        Alright Frank

        Can you just confirm this for us please...

        At the moment I have the above code supplied on the add_products page.. I do also have this bit of code on the same page..

        .= "product_date = ''";

        Then on the marketplace.php page see here Untitled Document

        This code used I beleive to get the information from the db filed?
        = ;

        I am correct? or confused??
        Not too sure about the $set statement but you would want to write your line I supplied as

        $product_date = date("Y-m-d", strtotime($_POST["$r[product_date]"]));

        At least I believe so.

        Frank
        {{ DiscussionBoard.errors[1720489].message }}
  • Profile picture of the author boo5td
    As fthomas137 said you can just use strtotime and the date function to do it, or another way to do it is to use 'explode' and rearrange the string, probably a little faster performance wise, but I doubt you would hardly notice it

    // assumes that product date is already in the format yyyy-mm-dd
    $dateToArrange=explode("-", $product_date);
    $newProductDate=$dateToArrange[1]."-".$dateToArrange[3]."-".$dateToArrange[2];
    echo "<br><br>New Format: $newProductDate <br>";
    {{ DiscussionBoard.errors[1713105].message }}
  • Profile picture of the author lisag
    SELECT DATE_FORMAT(mydate, '%d/%m/%Y') as mydate from mytable
    Signature

    -- Lisa G

    {{ DiscussionBoard.errors[1716800].message }}

Trending Topics