0

I tried display 1 monthly data but I want display e.g between 01.06.2013 and 01.07.2013 ? How to change this query for display between two date ? Thanks in advance

   select b.ID ID, bt.type BULTEN_TYPE, b.ID TOPIC, b.Bul_Effect EFFECTT, b.Bul_Comment COMMENTS, 

     concat(date_format(b.Bul_date,'%d.%m.%Y'), ' ', b.Bul_hour, ':', b.Bul_min) as BEGIN,      
     concat(date_format(b.bitdate,'%d.%m.%Y'), ' ', b.bithour
     , ':', b.bitmin) as FINISH from bulten b, bulten_type bt, statu s WHERE b.Bul_Type = bt.ID and   
      b.Status = s.ID and Bul_date >= date(now() - interval 1 month) order by ID desc;

4 Answers 4

2
 select b.ID ID, 
      bt.type BULTEN_TYPE,
      b.ID TOPIC,
      b.Bul_Effect EFFECTT,
      b.Bul_Comment COMMENTS, 
     concat(date_format(b.Bul_date,'%d.%m.%Y'), ' ', b.Bul_hour, ':', b.Bul_min) as BEGIN,
     concat(date_format(b.bitdate,'%d.%m.%Y'), ' ', b.bithour
     , ':', b.bitmin) as FINISH 
     from bulten b, bulten_type bt, statu s
      WHERE b.Bul_Type = bt.ID and   
      b.Status = s.ID and 
     Month(Bul_date)=Month(GetDate()) and Year(Bul_date)=Year(GetDate()) 
     order by ID desc;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you bro.But where I enter my dates ?
@MehmetAkyel it will automatically give u the curent month report if you want to provide your own range than give it in place of GetDate()
1

This WHERE clause will get you exactly what you used as an example:

... and Bul_date BETWEEN '1/6/2013' AND '1/7/2013' ...

Now, a more dynamic way of getting at what I think you want would be:

... and Bul_date BETWEEN GETDATE() AND DATEADD(DAY, 1, GETDATE()) ...

that would get you everything between now, and a day from now.

Now, the problem with the last example is that GETDATE() has a time on it so if you wanted to strip that (i.e. to start from midnight) you could do this:

... and Bul_date BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) AND
        DATEADD(DAY, 1, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))

Comments

1

use this

Bul_date BETWEEN @StartDate AND @EndDate;

Comments

1

I have find something for you. I think this might helps you

SQL check record in between two dates and time

Check this question

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.