If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Date stored in Char(11)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-16-09, 10:50
helloc++ helloc++ is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 03-16-09, 11:03
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You really need to change the datatype to the correct one.
Data Types -- The Easiest Part of Database Design
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 03-16-09, 11:16
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
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'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On