Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Understanding and Calculating Dates

The article explains how to automatically calculate when the next (or next N) business days are from a given date by calculating and storing this type of information in SQL Server. You will learn more about how SQL Server handles dates and about its functions.


advertisement
QL Server provides many sophisticated functions to calculate dates. But knowing how to use them can often be a challenge. Suppose you want to calculate when a package is due to arrive based on the shipping date and the type of shipping chosen. Because many shipment types don't include delivery on a weekend or holiday, you can't simply use the DATEADD() function to add a given number of days to the shipment date.

Using two-day shipping as an example, here's how I'd describe the algorithm you need: "Choose the first day that is two or more days greater than the shipping date that is not a weekend or holiday." That is, in fact, the way that you would do it manually. But how do you translate that instruction to SQL Server?

This 10-Minute Solution discusses a very common problem—calculating when the next (or next N) business days are from a given date. I'll show you how to automate the process by calculating and storing this type of information in SQL Server. In doing so, you will learn more about how SQL Server handles dates and about its functions that manipulate them.



How do you use SQL Server's date functions to calculate something as seemingly simple as "the next business day"?



Here are the steps to calculate the dates accurately:

  1. Create a table of days in your calendar.
  2. Populate the table with a row for each day in the calendar.
  3. Set the holidays correctly.
  4. Calculate the arrival dates.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date