Hi,
In real time business applications, we'll meet some scenarios like this. From our UI we'll send the Date time to the SQL Server to calculate the exact number of days different between today and the date passing by us.
Actually the GETDATE() function of SQL Server gives the Server's Date time in this format: 2011-01-26 11:43:13.397
The Date time sending from client UI will be like this: 2011-01-02 12:00:00.000
In real time business applications, we'll meet some scenarios like this. From our UI we'll send the Date time to the SQL Server to calculate the exact number of days different between today and the date passing by us.
Actually the GETDATE() function of SQL Server gives the Server's Date time in this format: 2011-01-26 11:43:13.397
The Date time sending from client UI will be like this: 2011-01-02 12:00:00.000
When we try to calculate the exact number of days different between these it'll take time too. This may be give wrong answer. In this situation we can ommit the time part of the both dates.
Here I wrote one SQL Server User Defined Function to achieve this.
CREATE FUNCTION [dbo].[UFN_GetExactDate] (@InputDate DATETIME)
RETURNS DATETIME
BEGINHere I wrote one SQL Server User Defined Function to achieve this.
CREATE FUNCTION [dbo].[UFN_GetExactDate] (@InputDate DATETIME)
RETURNS DATETIME
DECLARE @OutputDate DATETIME
SELECT @OutputDate= CAST(CONVERT(VARCHAR(25),@InputDate,101) AS DATETIME)
RETURN @OutputDate
END
We can use this UDF in our Stored procedures like this: SELECT [dbo].[UFN_GetExactDate](GETDATE())
This will give result like this: 2011-01-26 00:00:00.000
Hope this helps!
Comments
Post a Comment