Quantcast
Channel: Way 2 Resources - General
Viewing all articles
Browse latest Browse all 10

Select Only Date Part From A DateTime Value in Sql Server

$
0
0

Hi,

Many times we required to compare user inserted date value with our database datetime value, during showing these types of report because while comparing the values system compares the time values and will not show the desired values. To overcome from this problem we have to select only date part from our value then should compare the values then it will show the desired report. Here is a function by which anyone can terminate the time part from the datetime value stored in database and then compare only Dates and generate between date reports.

 

Create FUNCTION [dbo].[udf_OnlyTheDatPart]
(@d datetime) --returns just the date with no time
RETURNS datetime AS
BEGIN
return cast(convert(varchar,@d,110) as datetime)
END

 

We can give a Datetime value as a parameter in it and will get return as only date. We can assume this example as How To Terminate Time Part From DateTime Value. Now we can use this function in our report and get desired result while generating report for between date data.

 


Viewing all articles
Browse latest Browse all 10

Trending Articles