SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 cannot fetch dates in dd/mm/yyyy
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

manisha gangwar
Starting Member

India
3 Posts

Posted - 07/29/2010 :  06:14:05  Show Profile  Reply with Quote
hii,,

i have problem in fetching dates that are in dd/mm/yyyy format.
i m using query--

select * from tborc where date between '01/07/2010' and '11/07/2010'

the problem is that this query is not comparing months , it is comparing dates only.
like if date field has following data--

date(varchar)
----------
02/07/2010
10/07/2010
05/08/2010

then it should not take 05/08/2010.


webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 07/29/2010 :  07:11:07  Show Profile  Visit webfred's Homepage  Reply with Quote
You should really store dates as datatype datetime and format it only when displaying.
But to your problem
select * from tborc where convert(datetime,date,104) between convert(datetime,'01/07/2010',104) and convert(datetime,'11/07/2010',104)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17650 Posts

Posted - 07/29/2010 :  07:11:47  Show Profile  Reply with Quote
the problem is because you are storing date in varchar. Why not using datatime data type ?


KH
Time is always against us

Go to Top of Page

manisha gangwar
Starting Member

India
3 Posts

Posted - 07/29/2010 :  08:41:28  Show Profile  Reply with Quote
thanx ,, it worked
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 07/29/2010 :  08:42:10  Show Profile  Visit webfred's Homepage  Reply with Quote
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

manisha gangwar
Starting Member

India
3 Posts

Posted - 07/29/2010 :  08:43:08  Show Profile  Reply with Quote
as my pl told so!
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 07/29/2010 :  08:50:44  Show Profile  Visit webfred's Homepage  Reply with Quote
quote:
Originally posted by manisha gangwar

as my pl told so!


I think this is the answer to
Why not using datatime data type?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

navi1478
Starting Member

India
2 Posts

Posted - 06/11/2013 :  02:50:29  Show Profile  Reply with Quote
select * from tborc where convert(datetime,date,104) between convert(datetime,'01/07/2010',104) and convert(datetime,'11/07/2010',104)


I used this same query but create some issues
like

'01/07/2010' and '01/09/2010'
not showing 08 & 09 months data ..

Navi
Go to Top of Page

navi1478
Starting Member

India
2 Posts

Posted - 06/11/2013 :  02:57:17  Show Profile  Reply with Quote
Sorry this query is working fine .
error on my side

Thnx webfred

Navi
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 06/11/2013 :  03:18:12  Show Profile  Reply with Quote
quote:
Originally posted by navi1478

select * from tborc where convert(datetime,date,104) between convert(datetime,'01/07/2010',104) and convert(datetime,'11/07/2010',104)


I used this same query but create some issues
like

'01/07/2010' and '01/09/2010'
not showing 08 & 09 months data ..

Navi


this will cause the optimiser to ignore an idex if already present on date field

see

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000