The second argument is the number of intervals to add and can be a negative or positive integer. It takes three arguments, the first argument is the interval which can be any one of the following : This can be used to add a positive or negative interval of time to an existing datetime value and return a new one. So with that in mind lets look at the DATEADD function first. The first 4 bytes represent the number of days prior or since 1 st January 1900, and the remaining 4 bytes represent a count of 300ths of seconds since midnight. Therefore, the earliest date that can be stored as a datetime in Sql Server is 1 st January 1753 anything prior to that involves dealing with a crossover from Julian, Chinese and who knows what else, so if you fit into this category you will have to implement your own method for date manipulation and you will have a very long neck indeed.Īll dates are stored as two 4 byte integers. ![]() All dates of datetime data type in Sql Server are based on the Gregorian calendar which was adopted by Britain and it's American colonies midway through the year of 1752. In this article I will be looking at the three main date functions DATEADD, DATEPART and DATEDIFF (there is a fourth called DATENAME but I want to get to the end of this article before you fall asleep so I decided to leave it for another date and time! And no it doesn't foretell the name of your future blind date so it's not as interesting as it sounds anyway) Then I will be combining all three in a user defined function of our own by which time our necks will be well and truly stretched!įirstly it is useful to know about how dates are stored in Sql Server and why it is that way. Now if that wasn't enough rope to hang ourselves with, as of Sql Server 2000 we gained the ability to create our own user defined functions. ![]() ![]() Sql Server comes with a host of built in functions such as ISNULL, CONVERT and CAST.
0 Comments
Leave a Reply. |