Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2008

    Unanswered: converting date to display as m-d-y

    New with PHP and I have an input form in html and the output form is in PHP.
    On the input form I type 6-22-2008 for the date and when I hit the sumit button, it wants to store the date in the table as 2008-06-22. then when the table is shown I want to see the date as 06-22-2008.

    how do I change the 06-22-2008 to the 2008-06-22 to save in the table and then change it back for viewing and printing?


    Can I change the table to except the m-d-y format?

    I changed the code an I able to enter m-d-y and store it as y-m-d in the table. Now I want to get it from the table and display it as m-d-y. The below code show what I am doing.

    while ($row = mysql_fetch_array($result))
    				// list($year, $month, $day ) = split("-", "CDateCreated");
    				// $DATE = date('m-d-Y', mktime(0,0,0, $year, $month, $day));
    //here I am taking the date out of the table and converting it from
    y-m-d to m-d-y and I get from 2008-6-27 to 31-12-1969????
    and now do I get it into the diplay below?
    				echo "<TR>";
    				echo "<TD>", $row['CName'], "</TD><TD>",
    				echo "</TR>";
    Thanks for any help you can give me,

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    have a look at the php web site ( the date functions
    and date format. for get the detailsl but I think you go through mktime, and may have to use printf/sprintf + appropriate mask. bear in mind you have three separate problems.. storing the date in your DB, using the date within the app and how you present the date to a user.

    the storing in the db & use within a progrma should be via date variables/datatypes and the presentation is via a formatting
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2008
    I used the mktime to convert it from 6-1-2008 to 2008-6-1. I checked out the table and it was put into the table correctly. Its getting back to display I am having the problem with. I will look at


  4. #4
    Join Date
    Mar 2007
    Quote Originally Posted by rmartin
    how do I change the 06-22-2008 to the 2008-06-22 to save in the table and then change it back for viewing and printing?
    You can simply store the data normally using NOW() (Mysql function):
    INSERT INTO table_name (name, cur_date) VALUES('John', NOW())
    Then, pull the data back out in a format that you need:
    SELECT name, DATE_FORMAT(cur_date, '%d-%m-%y') as cur_date FROM table_name

  5. #5
    Join Date
    Aug 2008

    no need of all these things

    just use this code

    echo $end_date=date("m/d/ Y",strtotime($rsformember['add_date']));
    echo $end_date=date("d/m/ Y",strtotime($rsformember['add_date']));

    or you can change it just according to your need
    here add_date is field in database it will work fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts