Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comparing two dates, see if greater less than

Author  Topic 

Velnias
Yak Posting Veteran

58 Posts

Posted - 2008-10-16 : 07:12:33
What I wish to do is input 2 paramaters into sql.

I.e End Date and Current Date

if Current Date > End Date return false

else return true

Any Ideas

SQL2005

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-10-16 : 07:24:56
CREATE FUNCTION [dbo].[samplefn] ( @currentdate datetime, @enddate datetime )
RETURNS VARCHAR(5)
AS
BEGIN
return case when @currentdate>@enddate then 'true' else 'false' end
END

select [dbo].[samplefn] (getdate(),getdate()+1)
Go to Top of Page

ForkandBeard
Starting Member

10 Posts

Posted - 2008-10-17 : 16:56:40
Or to use the SQL boolean...

CREATE FUNCTION [dbo].[samplefn]
(
@dte1 datetime
, @dte2 datetime
)

RETURNS BIT
AS
BEGIN

DECLARE @blnReturn BIT

IF (@dte1 > @dte2)
BEGIN

SET @blnReturn = 0
END
ELSE
BEGIN

SET @blnReturn = 1
END

RETURN @blnReturn
END
GO

SELECT [dbo].[samplefn] (getDATE(),getDATE()-1)

Many Thanks
Mitchell
www.forkandbeard.co.uk
Go to Top of Page

onlyforme
Starting Member

25 Posts

Posted - 2008-10-18 : 01:41:19
select * from user_details where getdate()>dtae
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 01:49:02
quote:
Originally posted by ForkandBeard

Or to use the SQL boolean...

CREATE FUNCTION [dbo].[samplefn]
(
@dte1 datetime
, @dte2 datetime
)

RETURNS BIT
AS
BEGIN

DECLARE @blnReturn BIT

IF (@dte1 > @dte2)
BEGIN

SET @blnReturn = 0
END
ELSE
BEGIN

SET @blnReturn = 1
END

RETURN @blnReturn
END
GO

SELECT [dbo].[samplefn] (getDATE(),getDATE()-1)

Many Thanks
Mitchell
www.forkandbeard.co.uk


no need of if else...you could simply use case when just like what sakets have show in his post
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 01:49:34
quote:
Originally posted by onlyforme

select * from user_details where getdate()>dtae


did you read question at all?
Go to Top of Page

ForkandBeard
Starting Member

10 Posts

Posted - 2008-10-18 : 07:18:46
My suggestion was just to illustrate the use of the BIT variable as opposed to a VARCHAR.

Many Thanks
Mitchell
www.forkandbeard.co.uk
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 07:46:16
quote:
Originally posted by ForkandBeard

My suggestion was just to illustrate the use of the BIT variable as opposed to a VARCHAR.

Many Thanks
Mitchell
www.forkandbeard.co.uk


Ok. i was just suggesting another way
Go to Top of Page
   

- Advertisement -