Any PHP Coders Can Help Please?

by 5 replies
6
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??
#programming #coders #php
  • 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
    • [1] reply
    • 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??
      • [1] reply
  • 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>";
  • SELECT DATE_FORMAT(mydate, '%d/%m/%Y') as mydate from mytable

Next Topics on Trending Feed