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
 Select Date query between date range

Author  Topic 

bhanu2217
Starting Member

35 Posts

Posted - 2010-02-11 : 03:16:35
I am trying to write a query to search the database between data range and display the record, where date is in the format(DD-MM-YYYY)


SELECT *,date_format(post_time,'%d-%m-%Y Time:%H:%i:%s') as post FROM member_comment where (post_time between '12-02-2008' and '12-02-2009')

post_time is of type datetime

Please let me know where i am going wrong.
Also will this query work in the same way on mysql also?

www.JamboreeBliss.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 03:21:41
[code]SELECT *,post_time as post FROM member_comment where post_time between '20080212' and '20090212')[/code]

do the formatting at your front end

I assume you're using MS SQL in which case there's no date_format function available

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bhanu2217
Starting Member

35 Posts

Posted - 2010-02-11 : 03:55:03
Thank You

www.JamboreeBliss.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 03:56:49
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-11 : 04:10:17
quote:
Originally posted by bhanu2217

I am trying to write a query to search the database between data range and display the record, where date is in the format(DD-MM-YYYY)


SELECT *,date_format(post_time,'%d-%m-%Y Time:%H:%i:%s') as post FROM member_comment where (post_time between '12-02-2008' and '12-02-2009')

post_time is of type datetime

Please let me know where i am going wrong.
Also will this query work in the same way on mysql also?

www.JamboreeBliss.com


Are you using Mysql or SQL Server?


Madhivanan

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

- Advertisement -