SQL Server compare datetime.

Posted on 2007-07-23
Last Modified: 2010-03-20
I need to compare the getdate() with a stored date in a field and if they're on the same date and the getdate() time is < the field time (hh:mm) execute a stored procedure.

Example the data field date and time is

2007-07-23 04:00:00.000

and getdate() is 2007-07-23 03:00:00.000

exec storeProc2
Question by:lrbrister
    1 Comment
    LVL 32

    Accepted Solution

    Declare @dt  DateTime

    Select @dt = --whatever to grab the one you want

    if getdate() < @dt AND Year(getdate()) = Year(@dt) and Month(getdate()) = Month(@dt) and Day(Getdate()) = Day(@dt)
      Exec StoredProc2

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
    Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now