SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help! Date Format In Php

    how do i render a date field in MM/DD/YYYY format instead of the default YYYY/MM/DD


    thanks,
    DLG_1

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops I jumped the gun. By date field, do you mean mysql's date format for a field? Please clarify
    Last edited by cupid; Oct 22, 2001 at 14:30.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function date_format($date) {
      
    $array explode('/'$date);
      return 
    "$array[1]/$array[2]/$array[0]";

    Example of function use:

    PHP Code:
    <?php
    $date 
    '2001/12/31';
    $newdate date_format($date);
    print 
    $newdate// Prints '12/31/2001'
    ?>
    Hope that helps. There's probably a better with with the date() function, which is the best way to go if you make a move to timestamps (highly recommended. I dig those).

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL's dates are stored as YYYY-MM-DD, not YYYY/MM/DD
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh. Wasn't paying attention. Sorry.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL's dates are stored as YYYY-MM-DD, not YYYY/MM/DD
    Actually MySQL allows for relaxed syntax and will automatically convert YYYY/MM/DD to YYYY-MM-DD for you upon insert.

    http://mysql.he.net/documentation/my....html#DATETIME


    Even

    YYYY|MM|DD would get converted for you, basically any delimiter as long as its used between each element will convert for yo.
    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
  •