Date comparison
-
i want to company that if today date is greater than do step 1 and if not than do step 2 and i m doing this IF dbo.FormatDate(GETDATE()) > dbo.FormatDate('28/04/2006') --Step 1 ELSE --Step 1 but its not proper working i can do this with year, month and day individual comparison buts not proper way to acheive task. can anyone tell me that what's the mistake in above code:) dbo.FormatDate() is a function which extract only date from date and time. Thanks
-
i want to company that if today date is greater than do step 1 and if not than do step 2 and i m doing this IF dbo.FormatDate(GETDATE()) > dbo.FormatDate('28/04/2006') --Step 1 ELSE --Step 1 but its not proper working i can do this with year, month and day individual comparison buts not proper way to acheive task. can anyone tell me that what's the mistake in above code:) dbo.FormatDate() is a function which extract only date from date and time. Thanks
I'm guessing (becuase you've not provided the code) that FormatDate is a UDF that returns some value that you can test against. I don't know why you need to do this as you can check greater than/less than on a date already.
IF GETDATE() > '2006-04-28'
BEGIN
-- Do stuff
END
ELSE
BEGIN
-- Do other stuff
ENDI would recommend that you always use ISO dates (YYYY-MM-DD) - that way you don't get messed around with cultural specific problems. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
-
I'm guessing (becuase you've not provided the code) that FormatDate is a UDF that returns some value that you can test against. I don't know why you need to do this as you can check greater than/less than on a date already.
IF GETDATE() > '2006-04-28'
BEGIN
-- Do stuff
END
ELSE
BEGIN
-- Do other stuff
ENDI would recommend that you always use ISO dates (YYYY-MM-DD) - that way you don't get messed around with cultural specific problems. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
Thanks for ur comments i have solved the problem with this code SET Dateformat dmy IF GETDATE() > dbo.FormatDate('24/04/2006') BEGIN PRINT 'A' END ELSE BEGIN PRINT 'B' END Thanks Best Regards, Tariq Mahmood