Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Unanswered: Date stored in Char(11)

    Hi all,

    Unfortunatly in my application we are using Char(11) to store date in database , instead of using datatype "DATE " .

    Here goes exactly how my table look like.

    loandate ------- in dd/mm/yyyy
    ==========
    '09/03/2009'
    '10/03/2009'
    '11/03/2009'
    '12/03/2009'
    '13/03/2009'


    Now how can i query the records which are in between 10/03/2009 and 12/03/2009


    Can i query this as follows ( But no result .... )
    Code:
    select CONCAT(RIGHT(loandate,4),SUBSTRING(loandate,4,2),LEFT(loandate,2)) as loandate
    FROM mytable
    WHERE loandate >= '2009/03/10'
    and  loandate <= '2009/03/12'

    Thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You really need to change the datatype to the correct one.
    Data Types -- The Easiest Part of Database Design
    George
    Home | Blog

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    how can i query the records which are in between 10/03/2009 and 12/03/2009
    It's definitely best to change the data types if you can. If you're afraid of having to rewrite all the code then you could also add an extra field to the existing table and set the proper date there. If you don't want to alter the existing database at all then the following should work but it won't be efficient at:
    Code:
    select STR_TO_DATE(loandate,'%Y%m%d') as loandate
    FROM   mytable
    WHERE  STR_TO_DATE(loandate,'%d/%m/%Y') >= '2009-03-10'
           and  STR_TO_DATE(loandate,'%d/%m/%Y') <= '2009-03-12'

Posting Permissions

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