The following Query gives the difference between & dates in number of days which gives 731 as output as day difference shown in screen-shot. SELECT DATEDIFF(month, CAST('' as DATE), CAST('' as DATE)) as DATEDIFF The following example finds the difference between & dates in number of months which gives 24 as output as month difference shown in screen-shot. SELECT DATEDIFF(year, CAST('' as DATE), CAST('' as DATE)) as DATEDIFF The following Query gives the difference between & dates in number of years which gives 2 as output as year difference shown in screen-shot. Now let’s look at some examples how you can find different between 2 dates in year, month or day. If your input date is in string or number, please convert into date or timestamp as per format of it.ĭate2|timestamp2:- “To date or timestamp” for which you want to calculate difference. It supports DAT E, TIME, TIMETZ, or TIMESTAMP. Please use unit of date based on your business requirement.ĭate1|timestamp1:- “ From date or timestamp” for which you want to calculate difference. Like if you apply DATEDIFF on 01-01-2008 & 01-02-2008 with month unit it will return 1. It returns the difference between two date in BIGINT datatype. Unit_of_difference:- The specific unit of the date or time value like year, month, or day, hour, minute, second, millisecond, or microsecond Syntax of DATEDIFF DATEDIFF(unit_of_difference, date1|timestamp1, date2|timestamp2) DATEDIFF is used to get difference between the two date/timestamp in unit of year, month, or day, hour, minute, second, millisecond or microsecond.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |