none
sql query for date between RRS feed

  • Question

  • Hi,

    This is velsamy, i have created the aspx page for retrieve the data by using date's selection , i used the query like this

    SELECT * FROM report WHERE ( from_date BETWEEN '07/10/2012' AND '07/10/2012') OR ( from_date BETWEEN '07/10/2012' AND '07/10/2012') AND ( from_date= '07/10/2012') OR (from_date= '07/10/2012')

    is this query is correct or not? if it wrong kindly give me the correct  query. its urgent

    Thanks in advance,

    Velsamy

    • Moved by Shulei Chen Tuesday, September 11, 2012 12:57 AM (From:SQL Server Express)
    Monday, September 10, 2012 7:36 AM

Answers

  • Hi,

    This is velsamy, i have created the aspx page for retrieve the data by using date's selection , i used the query like this

    SELECT * FROM report WHERE ( from_date BETWEEN '07/10/2012' AND '07/10/2012') OR ( from_date BETWEEN '07/10/2012' AND '07/10/2012') AND ( from_date= '07/10/2012') OR (from_date= '07/10/2012')

    is this query is correct or not? if it wrong kindly give me the correct  query. its urgent

    Thanks in advance,

    Velsamy

    Simplify it to be

    SELECT * FROM report WHERE from_date=CONVERT(datetime,'07/10/2012',103)


    Many Thanks & Best Regards, Hua Min


    Tuesday, September 11, 2012 1:56 AM

All replies

  • Can you try

    SELECT * FROM report WHERE ( from_date BETWEEN '07/10/2012 00:00:00' AND '07/10/2012 23:59:59') 


    Regards,
    Ahmed Ibrahim
    SQL Server Setup Team
    My Blog
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
    This can be beneficial to other community members reading the thread.
    View Ahmed Ibrahim's profile on LinkedIn

    Monday, September 10, 2012 7:45 AM
  • it is working,

    I need more combinations

    Monday, September 10, 2012 1:15 PM
  • Please brief more about requirment.

    Please click the Mark as Answer or Vote As Helpful if a post solves your problem or is helpful!

    Monday, September 10, 2012 7:20 PM
  • If you want to select rows for particular date and you're using datetime type, then try

    select ColumnNames from dbo.Report where From_Date >='20120710' and From_Date < '20120711'

    This is assuming you wanted to select all rows for July 10th.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Tuesday, September 11, 2012 1:50 AM
    Moderator
  • Hi,

    This is velsamy, i have created the aspx page for retrieve the data by using date's selection , i used the query like this

    SELECT * FROM report WHERE ( from_date BETWEEN '07/10/2012' AND '07/10/2012') OR ( from_date BETWEEN '07/10/2012' AND '07/10/2012') AND ( from_date= '07/10/2012') OR (from_date= '07/10/2012')

    is this query is correct or not? if it wrong kindly give me the correct  query. its urgent

    Thanks in advance,

    Velsamy

    Simplify it to be

    SELECT * FROM report WHERE from_date=CONVERT(datetime,'07/10/2012',103)


    Many Thanks & Best Regards, Hua Min


    Tuesday, September 11, 2012 1:56 AM
  • You can also do a comparison with DATEADD.

    SELECT * FROM report WHERE from_date > DATEADD(DD,-1,YOUR-DATE-HERE)

    Tuesday, September 11, 2012 10:37 AM