Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:39:03+00:00 2026-06-08T22:39:03+00:00

I have datetime stored in my table in the fields LeaveFrom and LeaveTo for

  • 0

I have datetime stored in my table in the fields LeaveFrom and LeaveTo for leaves, something like

LeaveFrom = 05/26/2012 12:00:00 and LeaveTo = 06/30/2012.. and so on

From front end i am passing only Month and Year. So what will be the search condition for the same.

I need criteria for month and year wise searching. How many peoples applied for leave / or were absent in the particular month.

Thanks to all of you.. almost all were close to expected …thanks,what i need was a ‘HINT’.. thanks a ton to all of you guys..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:39:04+00:00Added an answer on June 8, 2026 at 10:39 pm

    As far as I can tell, you want all rows that has overlap between LeaveFrom and LeaveTo with the chosen month. I provided some sample dates as documentation.

    declare @yourtable table(LeaveFrom datetime, LeaveTo datetime)
    insert @yourtable values('2012-05-26 12:00:00', '2012-06-30')
    insert @yourtable values('2012-01-26 12:00:00', '2012-12-30')
    insert @yourtable values('2012-01-26 12:00:00', '2012-04-30')
    insert @yourtable values('2012-05-26 12:00:00', '2012-12-30')
    insert @yourtable values('2012-01-26 12:00:00', '2012-05-30')
    insert @yourtable values('2012-06-26 12:00:00', '2012-12-30')
    insert @yourtable values('2011-01-01 12:00:00', '2011-01-01')
    
    declare @month tinyint = 5
    declare @year int = 2012
    
    -- calculate a data corresponding to month and year (2012-05-01)
    declare @date datetime= dateadd(month, (@year-1900) * 12 + @month-1, 0)
    
    select * from @yourtable
    where datediff(month , LeaveFrom, @date) between 0 and datediff(month , LeaveFrom, LeaveTo)
    

    EDIT: another possible way with same result:

    select * from @yourtable
    where @date between dateadd(month, datediff(month, 0, LeaveFrom), 0) 
    and dateadd(month, datediff(month, 0, LeaveTo), 0) 
    

    Result:

    LeaveFrom               LeaveTo
    ----------------------- -----------------------
    2012-05-26 12:00:00.000 2012-06-30 00:00:00.000
    2012-01-26 12:00:00.000 2012-12-30 00:00:00.000
    2012-05-26 12:00:00.000 2012-12-30 00:00:00.000
    2012-01-26 12:00:00.000 2012-05-30 00:00:00.000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have stored date (java.util.date object) in a DATETIME field of a Sqlite table.
I have a table stored in SQL Server database. One of the fields of
I have dates in SQL stored as DateTime, when showing them in a textbox
I have stored a variable in database(sqlite) with datetime data type. Now I want
I have written a SQL Server stored procedure that includes a DateTime parameter. This
I have following stored procedure: CREATE PROCEDURE testProc(IN p_idProject INTEGER) BEGIN DECLARE nowTime DATETIME;
I currently have a list of DateTimes stored as the timezone's UTC datetime. When
Possible Duplicate: Format mysql datetime with php Well.. I have stored date(c) in Mysql
I have a datetime called dispatched_time which I am subtracting from Time.now which results
I have a DateTime? field. Its currently storing UT. I would like it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.