Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Sqlite
Hi,
 
I am using Sqlite with visual studio .net. I have a table in which a column data type is in datetime when I am using a query for between date it don't giving results. Query listed below:
 
1) SELECT itm_id, book_acc FROM boo_dmg_lost WHERE boo_date between'9/11/2012' and '9/13/2012'
 

2)SELECT itm_id, book_acc FROM boo_dmg_lost WHERE (boo_date > '9/23/2012') AND (boo_date < '9/13/2012')
 

Thanks in advance.
Posted 13-Sep-12 19:03pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Since the column is of DateTime type, try to compare it with dates and not string:
--DECLARE @startDate DateTime
--DECLARE @endDate DateTime

--SET @startDate = CONVERT(DateTime, '4/2/2011')

SELECT
  item_id, book_ac
FROM
  boo_dmg_lost
WHERE
  boo_date BETWEEN @startDate AND @endDate
If needed, read about datatype conversion: MSDN: CAST and CONVERT (Transact-SQL)[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I got the correct result.
 
First insert query is in the Format of yyyy-mm-dd hh:mm:ss.xxxxxx
e.g '2012-09-14 10:00:00.123123' and after that for reading we will have to give
query like this:
SELECT itm_id, book_acc FROM boo_dmg_lost WHERE strftime('%Y-%m-%d', boo_date) BETWEEN '2012-09-14' AND '2012-09-15'
Because simple date format of .Net for inserting date into database is not readable format so we will have to give insert query through given format and then read.
 
Thank You.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi ,
 
give to there below that,
 
1) SELECT itm_id, book_acc FROM boo_dmg_lost WHERE boo_date between'20120911' and '20120913'
 
2)2)SELECT itm_id, book_acc FROM boo_dmg_lost WHERE (boo_date > '20120923') AND (boo_date < '20120913')
 

now it should works.
Thanks
  Permalink  
Comments
coolboypankaj at 14-Sep-12 4:07am
   
Its working fine from sqlite but using with .NET its giving error "String was not recognized as a valid DateTime"
Unareshraju at 14-Sep-12 7:20am
   
use the explicit type conversion
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Have you checked this discussion[^]?
 
It looks like your first query is correct, the only problem is with the your date format. try with YYYY-MM-DD format. it will work as expected.
  Permalink  
Comments
coolboypankaj at 14-Sep-12 4:09am
   
I have checked all the formats but it didn't working.
@amitgajjar at 14-Sep-12 4:10am
   
what is the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 515
1 OriginalGriff 450
2 CHill60 305
3 Abhinav S 300
4 Sergey Alexandrovich Kryukov 294
0 Sergey Alexandrovich Kryukov 9,897
1 OriginalGriff 9,395
2 Peter Leow 5,162
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036


Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100