How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MyOracle

    How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

    Hi everybody,

    I just curious about change date(0000-00-00) to date (00-00-0000) in
    mysql.Can anyone tell me about that.

    Thanks.
    izmanhaidi.
  • Chris Hope

    #2
    Re: How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

    MyOracle wrote:
    [color=blue]
    > I just curious about change date(0000-00-00) to date (00-00-0000) in
    > mysql.Can anyone tell me about that.[/color]

    use strtotime() to convert the mysql datetime format into a timestamp, and
    then date() to convert it into your chosen format.

    eg print date(strtotime( $mysql_date), "d-m-Y"))

    Refer to the manual pages for more info at:

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Bill Karwin

      #3
      Re: How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

      MyOracle wrote:[color=blue]
      > I just curious about change date(0000-00-00) to date (00-00-0000) in
      > mysql.Can anyone tell me about that.[/color]

      Read about the DATE datatype and its relatives here:


      MySQL always stores and retrieves date values in YYYY-MM-DD format.
      You must use this format when inputting date values.

      You can reformat output of date values in a SELECT using the
      DATE_FORMAT() function. See:


      Regards,
      Bill K.

      Comment

      • Chris Hope

        #4
        Re: How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?

        Chris Hope wrote:
        [color=blue]
        > MyOracle wrote:
        >[color=green]
        >> I just curious about change date(0000-00-00) to date (00-00-0000) in
        >> mysql.Can anyone tell me about that.[/color]
        >
        > use strtotime() to convert the mysql datetime format into a timestamp, and
        > then date() to convert it into your chosen format.
        >
        > eg print date(strtotime( $mysql_date), "d-m-Y"))
        >
        > Refer to the manual pages for more info at:
        >
        > http://www.php.net/strtotime
        > http://www.php.net/date[/color]

        Actually Bill's post is better. I must have been half asleep when I read
        your post and was thinking I was posting a reply to a PHP group. If you are
        coding in PHP then my solution works in your PHP script, otherwise check
        out his post as you can reformat the date in MySQL itself.

        --
        Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

        Comment

        • Wouter

          #5
          Re: How to change date(yyyy-mm-dd) to date (dd-mm-yyyy) in mysql?


          SELECT DATE_FORMAT(pub date, '%e-%m-%Y') AS date FROM mytable
          for 5-09-2004

          SELECT DATE_FORMAT(pub date, '%d-%m-%Y') AS date FROM mytable
          for 05-09-2004

          I prefer the first one, so I can easilly replace the -09- by the month name
          in the page language.

          :)
          Wouter


          "MyOracle" <izmanhaidi@yah oo.com> wrote in message
          news:f502bdbf.0 410310815.472b3 1cd@posting.goo gle.com...
          : Hi everybody,
          :
          : I just curious about change date(0000-00-00) to date (00-00-0000) in
          : mysql.Can anyone tell me about that.
          :
          : Thanks.
          : izmanhaidi.


          Comment

          Working...