sql server query to determine if requested date and time are OK

Posted on 2013-01-22
Last Modified: 2013-01-22

I have a query which does not works:-

ALTER PROCEDURE [dbo].[stp_validate_DT_Requested]
      -- Add the parameters for the stored procedure here
      @DT_Requested as Date,
@Firsttime as Time,
 @Lasttime as Time
SET Dateformat YMD
if @DT_Requested >= GETdate() and @Firsttime <= @Lasttime

    SELECT '1' AS IsValid
    SELECT '0' AS IsValid

What i expect that it will do is to check if a requested date is bigger or the same as the current date and that the requested endtime is later then the start time. An agenda check.

What is wrong?
thanks for your help!
Question by:aatjan
  • 3
  • 2
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38804514
I see nothing "wrong" ...
please clarify how you call the procedure, and what you get as output, and what you expect as output.
maybe you get an error?
please clarify
LVL 25

Expert Comment

ID: 38804610
GetDate() returns also the time

Author Comment

ID: 38804908

This is what i'm entering when executing the query from studio:-

EXEC      @return_value = [dbo].[stp_validate_DT_Requested]
            @DT_Requested = '2013/01/22',
            @Firsttime = '09:00',
            @Lasttime = '10:00'

SELECT      'Return Value' = @return_value

I think that the return value should be a 1, because dtrequested is the current date.
and the lasttime is bigger then the first time ....

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

LVL 25

Assisted Solution

jogos earned 100 total points
ID: 38804999
Do this query to know what you are comparing with

select getdate(),CONVERT(datetime,'2013/01/22')

Open in new window


Author Comment

ID: 38805022
ok, so that is the reason why mydate is smaller ....
now we must get rid of the timepart of getdate. How to do that?

LVL 142

Accepted Solution

Guy Hengel [angelIII / a3] earned 400 total points
ID: 38805027

Author Comment

ID: 38805146
@AngelIII: found it and it works.


Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

25 Experts available now in Live!

Get 1:1 Help Now