SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change date/time to 20090401???

    How do I change a db tables date/time (2009-04-01 00:00:00) to 20090401??

    Is there a function?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That allmost did it... Now there is only one problem... If a date is 2009-04-01 it comes out like this: 2009041 without the zero infront of the one... How do I solve this?

    PHP Code:
    SELECT EXTRACT(YEAR_MONTH FROM matchstart) AS match_start,
                                    
    EXTRACT(DAY FROM matchstart) AS match_day FROM matches 

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See if this meets your needs.

    Code MySQL:
    CURDATE function

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    how do you solve it? there is nothing to solve

    dates are stored internally in a magic encryption that you need not know anything about

    what you need to know is how to format date values for output

    by default, you get a standard yyyy-mm-dd format

    if you want yyyymmdd, just use the DATE_FORMAT function

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  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)
    Code:
    SELECT DATE_FORMAT( matchstart, '%Y%m%d' ) as match_start from matches
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •