Convert a date format

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

    Convert a date format

    I am displaying records from a table including a stored date. When
    display $row[Date], i get the obvious 2006-05-21. However this is not
    what the guy wants. He wants 21-May-2006.

    I have tried several conversion functions but without success. I could
    do a long winded function, but i hoped there would be a simple
    solution.

    Any Ideas.

    Desmond.

  • David Haynes

    #2
    Re: Convert a date format

    Des wrote:[color=blue]
    > I am displaying records from a table including a stored date. When
    > display $row[Date], i get the obvious 2006-05-21. However this is not
    > what the guy wants. He wants 21-May-2006.
    >
    > I have tried several conversion functions but without success. I could
    > do a long winded function, but i hoped there would be a simple
    > solution.
    >
    > Any Ideas.
    >
    > Desmond.
    >[/color]




    -david-

    Comment

    • NC

      #3
      Re: Convert a date format

      Des wrote:[color=blue]
      >
      > I am displaying records from a table including a stored date. When
      > display $row[Date], i get the obvious 2006-05-21. However this is not
      > what the guy wants. He wants 21-May-2006.[/color]

      First of all, make it a habit to write $row['Date'], not $row[Date].
      The latter works for now, but may stop working in the future without
      warning. This said, the code snippet you are looking for can look like
      this:

      date('j-M-Y', strtotime($row['Date']))

      Cheers,
      NC

      Comment

      • Rik

        #4
        Re: Convert a date format

        Or strftime();

        Comment

        • Colin McKinnon

          #5
          Re: Convert a date format

          NC wrote:
          [color=blue]
          > Des wrote:[color=green]
          >>
          >> I am displaying records from a table including a stored date. When
          >> display $row[Date], i get the obvious 2006-05-21. However this is not
          >> what the guy wants. He wants 21-May-2006.[/color]
          >
          > First of all, make it a habit to write $row['Date'], not $row[Date].[/color]

          Good advice.
          [color=blue]
          > The latter works for now, but may stop working in the future without
          > warning. This said, the code snippet you are looking for can look like
          > this:
          >
          > date('j-M-Y', strtotime($row['Date']))
          >[/color]

          strtotime() is very americanized. And 32 bit timestamps suck. A better
          solution is to do the formatting in the DBMS if possible - assuming it's
          MySQL, then use the DATE_FORMAT() function for Oracle, TO_CHAR() - don't
          know about the rest.

          HTH

          C.

          Comment

          Working...