Thinking outside the box

Patron Saint of Lost Yaks
posts - 203, comments - 734, trackbacks - 4

My Links

Advertisement

News

Archives

Post Categories

A glance at SQL Server Denali CTP3 - DATEFROMPARTS

There is a new function in SQL Server Denali named DATEFROMPART. What is does, is to calculate a date from a number of user supplied parameters such as Year, Month and Date.

Previously you had to use a formula like this

DATEADD(MONTH, 12 * @Year + @Month - 22801, @Day)

to calculate the correct datevalue from the parameters. With the new DATEFROMPARTS, you simple write

DATEFROMPARTS(@Year, @Month, @Day)

and you get the same result, only slower by 22 percent. So why should you use the new function, if it's slower?
There are two good arguments for this

1) It is easier to remember
2) It has a built-in validator so that you cannot "spill" over the current month.

For the old way of doing this, using @Year = 2009, @Month = 2 and @Day = 29 you would end up with a date of 2009-02-28 and the DATEFROMPARTS will give you an error message.

Print | posted on Wednesday, July 13, 2011 9:18 AM | Filed Under [ Denali ]

Feedback

Gravatar

# re: A glance at SQL Server Denali CTP3 - DATEFROMPARTS

This great blog is very interesting and enjoyable to read. I am a big fan of the subjects discussed. I also enjoy reading the comments, but notice that a lot of people should stay on topic to try and add value to the original blog post. I would also encourage everyone to bookmark this page to your favorite service to help spread the word.
11/30/2011 3:11 PM | research papers
Gravatar

# re: A glance at SQL Server Denali CTP3 - DATEFROMPARTS

I have been looking for this,I loved to read your article.You must be putting a lot of time into your blog!
1/11/2012 11:44 AM | Profit By Outsourcing Web Design
Gravatar

# re: A glance at SQL Server Denali CTP3 - DATEFROMPARTS

This is helpful information to anybody that relies on SQL server technology. I can see how ensuring the date is correct can be a huge issue. Take for instance a software program that helps to create an employee schedule. If the date fields are not correct then the schedule that would be generated would be of no use. Thank you all for taking the time to spread your tips and helpful hints to the rest of the software community. Your hard work is appreciated.
1/28/2012 6:50 AM | employee schedule
Gravatar

# Online Shopping | Shop Online at India's largest Online Shopping site | Indiaplaza

Thanks for the information, I'll visit the site again to get update information
3/1/2012 1:01 PM | Online Shopping
Gravatar

# re: A glance at SQL Server Denali CTP3 - DATEFROMPARTS

If you test it with large data, you will notice that it is actually faster. Here is the proof beyondrelational.com/...
9/14/2012 7:45 AM | Madhivanan
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET