SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: now() Format

  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    now() Format

    Hi all, is it possible to format the way now() enters the format of the date and time into the database. It's going in as 2011-01-31 11:03. I want it to ideally be 31-01-2011 11:03. Any help is appreciated as always

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    In doesn't enter that way in the database at all. It's just the way the database shows the value to you.
    You can change the way it is presented to you using date_format

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guido, I've just tried formatting the date as my below example but now nothing is showing...?

    PHP Code:
    <?php echo date_format($orders['date_added'],'%b %d %Y %h:%i %p'?>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    date_format is a MySQL function...

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right ok, so I need to use that function when entering data to the database?

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coxdabd View Post
    Right ok, so I need to use that function when entering data to the database?
    No, when you pull it out of the database.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey dude, could you possibly show me an example of how this is done? Cheers

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT data_format( DateField, ... ) FROM testtable
    As posted above: http://dev.mysql.com/doc/refman/5.1/...on_date-format
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Massive help thanks, is there any I can incorporate this into a SELECT * FROM table as this is what I have used. Though I don't think that's best practice?

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by coxdabd View Post
    Massive help thanks, is there any I can incorporate this into a SELECT * FROM table as this is what I have used. Though I don't think that's best practice?
    Don't use the *

  11. #11
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okey dokey Thank you both for your help and advice.


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
  •