SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2001
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change 2001-11-23 to November 23, 2001 in php

    Hello,
    I have a mysql table with a column that records the date in yyyy-mm-dd format (date). I want to display the value in a php page but in the normal way (i.e. November 23, 2001). How can I do it?
    Guillermo

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this the mysql date type? If so, you can get there in a couple of steps with this...

    UNIX_TIMESTAMP()
    UNIX_TIMESTAMP(date)
    If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00' GMT). If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' GMT. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD in local time:
    mysql> select UNIX_TIMESTAMP();
    -> 882226357
    mysql> select UNIX_TIMESTAMP('1997-10-04 22:23:00');
    -> 875996580 When UNIX_TIMESTAMP is used on a TIMESTAMP column, the function will receive the value directly, with no implicit ``string-to-unix-timestamp'' conversion. If you give UNIX_TIMESTAMP() a wrong or out-of- range date, it will return 0.
    That should give you the result as a unix timestamp, that you can pass to date() to format any way you like.
    Andrew Thompson
    VPHost.com, part of the Untapped Resources Network.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you want to convert it to a unix timestamp just so you can turn around and convert using date()?

    You will be much better off using DATE_FORMAT() in your query to convert it to the format you want.

    http://www.mysql.com/documentation/m...time_functions

    Example
    Code:
    SELECT *, DATE_FORMAT(datefield, '%M %d, %Y') as formatted_date from tablename
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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