[SOLVED] Date formatting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SHOverine
    New Member
    • Sep 2006
    • 18

    [SOLVED] Date formatting

    Hello all,

    I have a table with a Date column and a Time column formatted as 'YYYY-MM-DD' and 'HH:MM:SS', respectively. I want to use php to print/ echo the date and time in the following format: "DayOfWeek. Month. DayOfMonth, Year, HH:MM PM" for example "Mon. Oct. 9, 2006 09:30 PM" (which is stored in the table as Col1 - 2006-10-09 and Col2 - 21:30:00).

    I attempted to get the Date column formatted with the following php code and I got the following error "Wrong parameter count for date() in web address at line 104.

    [php]
    <?php
    $sql1B = "SELECT Date FROM ShowTimes WHERE ShowID = $Show";
    $query1B = mysql_query($sq l1B);
    $Date1 = mysql_result($q uery1B, 0);
    echo date(D. M. j, Y, $Date1);
    ?>
    [/php]

    $Show is a variable that the user selected earlier on the web page.

    Any suggestions are greatly appreciated.

    Cheers,
    Seth
    Last edited by ronverdonk; Oct 13 '06, 07:31 PM. Reason: solved
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Another way: select the correct format directly from MySQL and echo $row['date'] and $row['time'] in PHP.
    Code:
    SELECT DATE_FORMAT(Col1, "%a. %b. %e, %Y") AS date, 
    DATE_FORMAT(Col2, "%I%:%i %p") AS time 
    FROM table_name
    Ronald :cool:

    Comment

    • SHOverine
      New Member
      • Sep 2006
      • 18

      #3
      I tried this method and I always get a parse error, unexpected T_STRING on line 103 (the first line of code):
      [php]
      mysql_query(SEL ECT DATE_FORMAT(col 1, "%a. %b. %e, %Y") AS Date
      FROM Shows WHERE ShowID = '$ShowID1');
      echo $row(Date);
      [/php]

      any suggestions are greatly appreciated.

      Cheers,
      Seth

      Comment

      • SHOverine
        New Member
        • Sep 2006
        • 18

        #4
        I got it! I changed the double quote to a single quote to get the following code. I had to convert the Date and Time columns into one DATETIME column.
        [php]
        <?php
        $sql1B = "SELECT DATE_FORMAT(Dat eTimes, '%a. %b. %e, %Y - %I%:%i %p') AS DateTimes
        FROM Shows WHERE ShowID = '$Show1'";
        $query1B = mysql_query($sq l1B);
        $DateTimes1 = mysql_result($q uery1B, 0);
        echo $DateTimes1;
        ?>
        [/php]

        Thanks for the help, Ron.

        Cheers,
        Seth

        Comment

        Working...