How to Check Whether a Month Falls Between Two Dates in Oracle

Oracle PL-SQL lets you query a database and determine if a month falls between two dates. The month can be in integer format or you can use the entire month, day and year to query the database. Use the "select" statement to query the information; if the date falls between two specified dates, the data returns from the database.

Instructions

    • 1

      Open the Oracle Enterprise Manager software from the Windows Program menu or open your preferred PL-SQL software. Log in to your Oracle database.

    • 2

      Set up the date with the month you want to evaluate. For instance, if you have the month of May, the program uses the integer "5" to represent May. The following code uses the numeric representation of the month and creates a date from the value:

      declare mydate date;
      mydate := TO_DATE ('1-5-2011','mm-dd-yyyy');

      Because you just want to evaluate the month, set the rest of the date to any day within the month. The year must fall between the two dates, so the year must be specified to query between two dates. In this example, the year "2011" is used.

    • 3

      Query the Oracle data to determine if the month falls between two dates. For instance, the following query returns "Yes" if the month variable falls between January and June 2011:

      select 'Yes' as Answer where mydate between to_date ('2011/01/01', 'yyyy/mm/dd') AND to_date ('2011/06/01', 'yyyy/mm/dd');

    • 4

      Click the "Run" button to execute the PL-SQL. In this example, the query returns "Yes" to verify that the month is between the two dates.

Related Searches:

References

Comments

Related Ads

Featured