Current location: Hot Scripts Forums » Programming Languages » Everything Java » applying Date range on string dates.


applying Date range on string dates.

Reply
  #1 (permalink)  
Old 11-05-09, 03:13 AM
sbutt sbutt is offline
New Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
applying Date range on string dates.

hi folks,
I have a table in mysql 5, which contains some date value (dd.mm.yyyy), but the column type is varchar. Now i want to query certain rows based on a given date range.

My query is the following:

Code:
SELECT integra_msg_monitor.msg_name, integra_msg_monitor.msg_date, integra_msg_monitor.msg_time FROM IntegraDB.integra_msg_monitor integra_msg_monitor where integra_msg_monitor.msg_date  BETWEEN  date_format(str_to_date('23.10.2009', '%d.%m.%Y'), '%d.%m.%Y') AND date_format(str_to_date('27.11.2009', '%d.%m.%Y'), '%d.%m.%Y')
The problem is that not all the correct rows are returned. Few rows are missing, e.g. i have a row with dates like 04.11.2009, which is not returned by this above query.

The problem in my opinion is that the BETWEEN clause is treating the dates as string (as the column type is varchar) and hence not returning the correct rows.

So is there anyway to treat the string column as "datatime" at runtime and do the BETWEEN query in order to get the correct values within the given data range?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-12-09, 03:29 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
You may find solution here

SOLUTION IS HERE !

make temp table at runtime or create view and insert the value into with converted form then run query on that. It may help you to get result.

Regards
__________________
Regards,
Mohit (ashwani)

Last edited by Nico; 11-13-09 at 08:15 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP C-Sharp DB Access Wrapper Question digioz ASP.NET 1 09-08-08 09:54 AM
search function using dot net nishudude_13 Windows .NET Programming 1 08-28-08 11:28 AM
list all dates - date range lool49 PHP 3 11-12-04 07:53 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 05:49 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.