Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Basic Date display problem

    Hi,

    I want to input my date in the typical American std
    format of mm/dd/yyyy e.g. 03/25/2013

    I then save this in the MySQL database table using:

    PHP Code:
    $sql "UPDATE `pages` SET 
    pub_date   = STR_TO_DATE('$Db_pub_date', '%m/%d/%Y')
    WHERE page_id = '$Db_page_id' "

    The record is a "date" format record so when I look at the table
    I can see it is stored as 2013-03-25

    Now my question:

    When I come to modify that record I extract it from the table and it
    looks like: 2013-03-25

    e.g.
    PHP Code:
    $N_pub_date  $row['pub_date']; 
    How do I get this back into the format: mm/dd/yyyy
    i.e. 03/25/2013

    So that I can then edit it, maybe make it 03/28/2013

    Thanks.



    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,595
    Thanks
    23
    Thanked 646 Times in 645 Posts
    PHP Code:
    $originalDate "2013-03-25";  // OR $row['pub_date']
    $newDate date("m/d/Y"strtotime($originalDate));
    echo 
    $newDate

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    This format is the best: YYYY-MM-DD

  • #4
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thank you very much
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by jeddi View Post
    The record is a "date" format record so when I look at the table
    I can see it is stored as 2013-03-25
    No it isn't - that's the format it gets converted back into when you extract it from the database without specifying a format.

    Quote Originally Posted by jeddi View Post
    When I come to modify that record I extract it from the table and it
    looks like: 2013-03-25
    .
    Specify the format you want the SELECT to return the date in so it doesn't use the default.

    SELECT DATE_FORMAT('%m/%d/%Y',pub_date) ...
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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