Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Formatting Dates

    I'm trying to format my date in a database table. Is there a way to do it in the mysqladmin or how do you have to do? It appears right now like 2008-08-08 but I want it to appear like July 8, 2008

    I have it in my php code as:

    <p><b>Date Won</b><br>'.$row['datewon'].'
    Last edited by CoolAsCarlito; 08-08-2008 at 03:36 AM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Where you fetch datewon from the query, just modify it to

    SELECT field1, field2, etc, DATE_FORMAT('datewon', '&#37;M %e, %Y') WHERE whatever='who';

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    After I put this in and tried to run it. It said that there was an unexpected T_String

    $query = 'SELECT *, DATE_FORMAT('datewon', '&#37;M %e, %Y') FROM titles';

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Change the 1st and last single quotes to double ones, eg " instead of '

    $query = "SELECT *, DATE_FORMAT('datewon', '&#37;M %e, %Y') FROM titles";

    The single quotes in the date_format() were breaking the line

  • Users who have thanked Nightfire for this post:

    CoolAsCarlito (08-08-2008)

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    I got it to show atleast but it isn't formatting it correctly still.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Ok, try this maybe

    PHP Code:
    $query "SELECT *, DATE_FORMAT('datewon', '%M %e, %Y') AS dateofwin FROM titles"
    Then call $row['datewon'] as $row['dateofwin'] instead

    I'm doing this completely off memory as haven't done this for about 5 years

  • Users who have thanked Nightfire for this post:

    CoolAsCarlito (08-08-2008)


  •  

    Posting Permissions

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