how to substring date in database

Discussion in 'MySQL' started by seo-india, Aug 16, 2010.

  1. #1
    Dear user how to used substring fuction on the date
     
    seo-india, Aug 16, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Using substring directly onto a date/datetime column , treated as a string, isn't good idea.

    DATETIME can be represented in different ways, depends on internal MySQL date_format configuration:
    So, it's better using functions like YEAR(),MONTH(),DAY(),HOUR(),MINUTE()... to extract desired portions and then concatenate them.Example:
    
    SELECT CONCAT(YEAR(NOW()),'-',MONTH(NOW()),'-',DAY(NOW())) AS DESIRED;
    
    Code (markup):
    Regards :)
     
    koko5, Aug 17, 2010 IP
  3. seo-india

    seo-india Banned

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    thanks for given answer but i am not satisfied this

     
    seo-india, Aug 18, 2010 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    What is your requirement?

    You can also use DATE_FORMAT() function to get the desired output.

    Some examples from the MySQL Manual
     
    mwasif, Aug 27, 2010 IP