SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Format Date???

  1. #1
    SitePoint Enthusiast rutters's Avatar
    Join Date
    Nov 2002
    Location
    ct
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Format Date???

    Code:
     
    $sql = "
    SELECT DATE_FORMAT(ShowDate,' %b %D %y  ')  
    AS PrintDate, ShowDate, ShowVenue, ShowLocation, ShowTime, ShowComments
    FROM ShowDates
    WHERE ShowDate >= CURDATE()
    ORDER by ShowDate ASC
    ";
    I cant get the date format to come out as Month, Day, and 2 digit year.

    Its coming out 2003-10-04. Which is the unix date format.


    Help!!

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, are you sure you are looking at the first column in the select list, PrintDate?

    SELECT
    DATE_FORMAT(ShowDate,' %b %D %y ') AS PrintDate,
    ShowDate,
    ...
    means that some variable $row["ShowDate"] (or whatever) will contain the unformatted date

    Its coming out 2003-10-04. Which is the unix date format.
    Looks more like the ISO 8601 date format

  3. #3
    SitePoint Enthusiast rutters's Avatar
    Join Date
    Nov 2002
    Location
    ct
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no column name in the table called PrintDate - only ShowDate - so Im confused why I even need PrintDate??

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, there's no column in the table, that's why I wrote "first column in the select list"

    You need the PrintDate "calculated" field because you want the formatted date to print out
    The column you don't need to select in the query is ShowDate (unless used for some purpose in your script/program)

  5. #5
    SitePoint Enthusiast rutters's Avatar
    Join Date
    Nov 2002
    Location
    ct
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But its from the ShowDate column that I want to format the date

    Would printdate take the date from ShowDate and format it?

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more time...

    Your sql statement looks like this:
    SELECT
    DATE_FORMAT(ShowDate,' %b %D %y ') AS PrintDate,
    ShowDate,
    ShowVenue,
    ShowLocation,
    ShowTime,
    ShowComments
    FROM ShowDates
    WHERE ShowDate >= CURDATE()
    ORDER by ShowDate ASC

    OK, when you get the result from the DB, the field called PrintDate (the alias for the result from the date_format() function) contains the formatted value of ShowDate, while ShowDate is the unformatted value (and I don't know if you really need this one in the sql above).

    Better explanation?

  7. #7
    SitePoint Enthusiast rutters's Avatar
    Join Date
    Nov 2002
    Location
    ct
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah I understand what you are saying and I tried taking it out but I got an error....

    http://vibe-raiders.com/shows.htm

  8. #8
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like it's working now?


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
  •