I want to diplay particular records between two dates using nvarchar
-
Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..
-
Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..
Samiullah wrote:
create table rough(checkeddate nvarchar(100))
Why are you storing date as an
nvarchar
? Try using adatetime
type instead and you can easily filter records using the query you mentioned. But if you still want to achieve it using an nvarchar, you can simply cast the value to adatetime
. Here's a small change to your query:select * from rough where cast(checkeddate as datetime) between '1/01/2006' and '12/31/2006'
Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
modified on Thursday, November 13, 2008 8:22 AM
-
Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..
as Syed said - STORE YOUR DATES AS DATETIME. This is a fundamental error in design and you should be smacked for using nvarchar. You are now going to forever need to cast/convert that column to do anything with it. More emphasis - USE THE CORRECT DATA TYPE
Never underestimate the power of human stupidity RAH
-
Hi, I have created a table and in that i have inserted some records. then i want to display the records between specified dates then how to do that. create table rough(checkeddate nvarchar(100)) These are the inserted values.. insert into rough values('1/01/2002') insert into rough values('3/01/2002') insert into rough values('12/01/2003') insert into rough values('11/09/2006') insert into rough values('8/01/2008') insert into rough values('1/01/2004') insert into rough values('1/01/2006') insert into rough values('1/21/2003') insert into rough values('1/31/2005') insert into rough values('1/11/2006') insert into rough values('1/01/2006') insert into rough values('1/01/2002') insert into rough values('1/01/2004') insert into rough values('1/01/2006') The output as follows mm/dd/yyyy ---------- 12/01/2003 11/09/2006 1/01/2006 1/21/2003 1/31/2005 1/11/2006 1/01/2006 1/01/2006 so my requirement is now i want to diplay particular records between two dates like as follows select * from rough where checkeddate between '1/01/2006' and '12/31/2006' Can anyone help me..
Yeah, what they said... or at least use an ISO 8601 compliant format YYYY-MM-DD.
-
Samiullah wrote:
create table rough(checkeddate nvarchar(100))
Why are you storing date as an
nvarchar
? Try using adatetime
type instead and you can easily filter records using the query you mentioned. But if you still want to achieve it using an nvarchar, you can simply cast the value to adatetime
. Here's a small change to your query:select * from rough where cast(checkeddate as datetime) between '1/01/2006' and '12/31/2006'
Regards, Syed Mehroz Alam
My Blog My Articles Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
modified on Thursday, November 13, 2008 8:22 AM