Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Displaying Objects within a Date Range

Displaying Objects within a Date Range

Scheduled Pinned Locked Moved Database
helpdatabasequestioncareer
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aptiva Dave
    wrote on last edited by
    #1

    Here is my problem: I have a job posting board that displays job postings for a certain about of time. Each posting in the database has a start date and an end date. Both are datetime fields that contain the time of 00:00:00.0000. Now, when i go to display these jobs on the site I use the following query to get them:

    SELECT     TOP (10) Jobs.jobID, Job\_Display.displayID, Jobs.title, Entity.entityName, Jobs.location
    

    FROM Entity INNER JOIN
    Jobs ON Entity.entID = Jobs.entID INNER JOIN
    Job_Display ON Jobs.jobID = Job_Display.jobID
    WHERE datediff(dd, getdate(), job_display.endDate) > -1 AND (Job_Display.display = 1)
    order by job_display.displayID desc

    Here is there the problem is: Say a job ended today (11/30/2011) it won't show up on the site, but what is intended is that it will be on the site until 12/1/2011. What do I need to change in the where clause to fix this issue?

    C J P M 4 Replies Last reply
    0
    • A Aptiva Dave

      Here is my problem: I have a job posting board that displays job postings for a certain about of time. Each posting in the database has a start date and an end date. Both are datetime fields that contain the time of 00:00:00.0000. Now, when i go to display these jobs on the site I use the following query to get them:

      SELECT     TOP (10) Jobs.jobID, Job\_Display.displayID, Jobs.title, Entity.entityName, Jobs.location
      

      FROM Entity INNER JOIN
      Jobs ON Entity.entID = Jobs.entID INNER JOIN
      Job_Display ON Jobs.jobID = Job_Display.jobID
      WHERE datediff(dd, getdate(), job_display.endDate) > -1 AND (Job_Display.display = 1)
      order by job_display.displayID desc

      Here is there the problem is: Say a job ended today (11/30/2011) it won't show up on the site, but what is intended is that it will be on the site until 12/1/2011. What do I need to change in the where clause to fix this issue?

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Just a suggestion. The call to getDate is also going to include the current time. Have the time component truncated or set to '00:00:00.0000' as well. :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

      1 Reply Last reply
      0
      • A Aptiva Dave

        Here is my problem: I have a job posting board that displays job postings for a certain about of time. Each posting in the database has a start date and an end date. Both are datetime fields that contain the time of 00:00:00.0000. Now, when i go to display these jobs on the site I use the following query to get them:

        SELECT     TOP (10) Jobs.jobID, Job\_Display.displayID, Jobs.title, Entity.entityName, Jobs.location
        

        FROM Entity INNER JOIN
        Jobs ON Entity.entID = Jobs.entID INNER JOIN
        Job_Display ON Jobs.jobID = Job_Display.jobID
        WHERE datediff(dd, getdate(), job_display.endDate) > -1 AND (Job_Display.display = 1)
        order by job_display.displayID desc

        Here is there the problem is: Say a job ended today (11/30/2011) it won't show up on the site, but what is intended is that it will be on the site until 12/1/2011. What do I need to change in the where clause to fix this issue?

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        I would suppose.... where (getdate() < job_display.endDate)

        1 Reply Last reply
        0
        • A Aptiva Dave

          Here is my problem: I have a job posting board that displays job postings for a certain about of time. Each posting in the database has a start date and an end date. Both are datetime fields that contain the time of 00:00:00.0000. Now, when i go to display these jobs on the site I use the following query to get them:

          SELECT     TOP (10) Jobs.jobID, Job\_Display.displayID, Jobs.title, Entity.entityName, Jobs.location
          

          FROM Entity INNER JOIN
          Jobs ON Entity.entID = Jobs.entID INNER JOIN
          Job_Display ON Jobs.jobID = Job_Display.jobID
          WHERE datediff(dd, getdate(), job_display.endDate) > -1 AND (Job_Display.display = 1)
          order by job_display.displayID desc

          Here is there the problem is: Say a job ended today (11/30/2011) it won't show up on the site, but what is intended is that it will be on the site until 12/1/2011. What do I need to change in the where clause to fix this issue?

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          How about WHERE GETDATE() BETWEEN startDate AND endDate? BETWEEN is inclusive. Also, (if SQL Server) maybe look nito the DATE datatype.

          1 Reply Last reply
          0
          • A Aptiva Dave

            Here is my problem: I have a job posting board that displays job postings for a certain about of time. Each posting in the database has a start date and an end date. Both are datetime fields that contain the time of 00:00:00.0000. Now, when i go to display these jobs on the site I use the following query to get them:

            SELECT     TOP (10) Jobs.jobID, Job\_Display.displayID, Jobs.title, Entity.entityName, Jobs.location
            

            FROM Entity INNER JOIN
            Jobs ON Entity.entID = Jobs.entID INNER JOIN
            Job_Display ON Jobs.jobID = Job_Display.jobID
            WHERE datediff(dd, getdate(), job_display.endDate) > -1 AND (Job_Display.display = 1)
            order by job_display.displayID desc

            Here is there the problem is: Say a job ended today (11/30/2011) it won't show up on the site, but what is intended is that it will be on the site until 12/1/2011. What do I need to change in the where clause to fix this issue?

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Convert GetDate() to a date to get rid of the time component (assumes SQL Server 2008).

            SELECT CONVERT(DATE,GETDATE())

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups