Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Dear All,I have the following scenario..,I have an input as date. If the user can enter any date in that input box. now i just need to validate the date like following For future datethe input date should not exceed the first day of the next monthEg:Current date 12/12/2006input date : 12/12/2008the o/p Should be 01/01/2007for Past dateThe input sholud not exceed before two months otherwise 60 dayseg:Current date : 12/12/2006input date : 01/01/2006the o/p should be 12/10/2006 (ie) 60 days differenceNote: I want to validate through sql only . No need of Front end..!can any one able to help me please. Urgent situationThanksKrishnaKrishnakumar.C
But for this scenario it fails..,Declare @dt DatetimeSelect @Dt = '2007/11/01'if month(@dt) = month(Getdate()) Begin Select @dt = @dt EndElse if month(@dt) > Month(Getdate()) Begin SELECT DATEADD(month, DATEDIFF(month, 0, getdate()), 31) EndElse if month(@dt) < Month(Getdate()) Begin SELECT DATEADD(day, DATEDIFF(day, 61, getdate()), 0) End
CSK
Constraint Violating Yak Guru
489 Posts
Posted - 2006-12-12 : 04:45:25
for the above scenario also i have to set the date as 01/01/2007ThanksKrishna
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-12-12 : 05:34:16
Write a proper algorithm/logic will help. You only compare month, but not year.Try this