Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem in Date

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2008-12-15 : 06:35:11
I m using My SQL.
Here Date is a column and its datatype is varchar.

i have to compare the date
as in SQl server

select * from tablename where date between '1/1/2008' and '5/5/2008'
how to query in My Sql .plz help me


Ved Prakash Jha

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-15 : 06:53:50
select * from tablename where convert(datetime , date) between '1/1/2008' and '5/5/2008'

select * from @tb where cast(date as datetime) between '1/1/2008' and '2/5/2008'
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-12-15 : 07:00:29
Thnks 4 query...
but it will work on sql server
i need query for my sql...

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-15 : 07:15:47
then you must be posting this on MySQL forums like www.dbforums.com
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-15 : 07:21:25
sorry vedjha, i don't know it will work in mysql or not
my query will work in sql 2005
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-15 : 09:18:08
quote:
Originally posted by vedjha

I m using My SQL.
Here Date is a column and its datatype is varchar.

i have to compare the date
as in SQl server

select * from tablename where date between '1/1/2008' and '5/5/2008'
how to query in My Sql .plz help me


Ved Prakash Jha


In MYSQL

select * from tablename
where cast(date as date) >='2008-01-01' and cast(date as date)<'2008-05-06'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-17 : 10:26:47
Hi

Use like this

select * from tablename where cast( date as datetime) between '1/1/2008' and '5/5/2008'

Be cool...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 10:45:09
quote:
Originally posted by raky

Hi

Use like this

select * from tablename where cast( date as datetime) between '1/1/2008' and '5/5/2008'

Be cool...


and how do you think this is different from what bklr posted 2 days back?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-24 : 02:04:15
quote:
Originally posted by raky

Hi

Use like this

select * from tablename where cast( date as datetime) between '1/1/2008' and '5/5/2008'

Be cool...


See my previous reply which is more effecient

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -