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 4 of 4
  1. #1
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

    Simple Date Question (Changing Formats)

    Hey everyone.

    In my MySQL table I have a date-type column where I think I am storing dates incorrectly. I save them as something like 1986-03-26

    I read up a bit and it seems this type is meant to have a timestamp... no?

    Anyways, I can echo the date out as "1989-03-26" perfectly fine, but I want to say :

    PHP Code:
    echo date("d F Y",$date); 
    This gives me 31 December 1986... not cool.

    Anyone know of a solution?

    Thanks a lot!
    -DR.Wong

    Wheres the food at?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    MySQL's date field type uses the format YYYY-MM-DD. I don't know who told you it should be a timestamp, but they're mistaken. You can generate a timestamp when you select the date if that's what you want:
    Code:
    SELECT UNIX_TIMESTAMP(`datecolumn`) AS `timestamp` FROM `table` WHERE 1

  • #3
    New Coder
    Join Date
    Jan 2003
    Location
    Orem, Utah
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The 2nd argument in the date function accepts a timestamp. You can either do as Inigoesdr suggested above and have the database return you a timestamp or do this instead with your regular date

    Code:
    echo date("d F Y",strtotime($date));
    perl -e "print pack(q!C!, hex($_)) for split / /, q!72 71 36 30!"

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    echo date("d F Y",strtotime($date));
    This is just plain silly, it's wasting server resources.

    MySQL allows you to format the date in the query.

    Look up DATE_FORMAT() (for MySQL).


  •  

    Posting Permissions

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