SQL Server 2005: Date Only

by Bryan Sever 6/23/2009 10:08:03 AM

In the business world, many reports are date and time sensitive. At times, all that matters is the date or the number of days difference from the current point and time.

This frequently creates the situation where the time portion of the datetime field type does not need and should not examine the time portion of this data type. When running a comparison in SQL Server 2005 for example, June 23rd at 1:00 A.M. is not the same as June 23rd at 12:00 A.M.

Therefore, it becomes necessary to compare the date portion of this type.

The official SQL Server Books online documentation states regarding the datetime type: "The first 4 bytes store the number of days before or after the base date: January 1, 1900."

Note the following examples executed in Query Analyzer application:

select convert(datetime, 39988) 
- output: 2009-06-26 00:00:00.000

select convert(datetime, 39988.5) 
- output:2009-06-26 12:00:00.000

select convert(datetime, 39988 + 14) 
- output:2009-07-10 00:00:00.000

select floor(convert(numeric(18,9),getdate())) 
- output:39985

select convert(datetime, floor(convert(numeric(18,9), getdate() + 14))) 
- output: 2009-07-07 00:00:00.000

The first example shows that a whole number produces a date and time that is 39988 days beyond January 1, 1900. It also shows that a whole number produces no time element in the datetime evaluation.

The second example show that providing a partial number (in this case 1/2) moves the hours to the time elapsed during the day (0.5 = 12 hours).

The third example shows adding 14 days to the previous input.

The fourth example shows getting the current system date and truncating the decimal portion.

The fifth example shows adding 14 days to the current date, truncating the time/decimal portion and then converting the numeric result back to the datetime type.

One consideration for these snippets is to create a SQL Server function that abstracts the conversion process.

Tags:

T-SQL | Microsoft SQL Server | Programming

Determination Rock

by Bryan Sever 4/11/2009 7:02:27 PM

April 11, 2009 - Determination Rock is just located off of Mill Canyon Road just a bit north of Moab, Utah. There are a few good family options nearby. There are even fossilized dinosaur bones that can be plainly seen just a bit off route. There are plenty of signs to get to the main destinations. However, there are fewer signs to get to Determination Rock.

We took three jeeps on this short course to get to the rock. There was one point where the wash that is travelled to get to the rock had some potential tire hazards. It is a good idea to have a spotter in this area. From the state road, it is a short journey. Near the end of the journey, there is a minor climb on the slick rock which still may need to be spotted for novice drivers.

It is a pleasant place to have a lunch. Our group spent well over an hour there. There was a geocache site nearby.

Be wary of bicyclists who take both sides of the road and don't like to share. They may signal you their displeasure if you don't let them have both sides of the road.

On the other side of the state road, there are some nice washes perfect for running your jeep.

Tags: , , , , ,

Vacation | Moab

Delicate Arch

by Bryan Sever 4/11/2009 7:42:34 AM

The beautiful arch that you see pictured at the top of each page on this web site is the world-famous delicate arch. It is located in Arches National Park just outside of Moab. On the way to the arch and as we were travelling through the park, there was big horn sheep right next to a warning sign that says there may be big horn sheep around.

After a few minutes journey, park visitors see the Balanced Rock. A bit beyond that, is the trailhead to Delicate Arch. For park users that do not wish to hike, there is a nearby lookout to which they can drive. We chose to take all the children on the hike. Even with the young children, the hike only took about one hour. We stayed there for an hour. There were plenty of hikers from all types of nationalities and origins enjoying this natural wonder.

Tags: , , ,

Vacation | Moab

Around Town

by Bryan Sever 4/10/2009 7:31:36 AM

April 9, 2009 - Moab has several parks. One is located at 100 West and 400 North. It isn't far off the main street. A few of us went to the park for a few hours. The five-year old, three-year old and infant were all in their delight. The park had plenty of good playground equipment for those age groups. On one end of the park, there is a skateboard park and a covered stage. Centered in the park is the playground equipment. There is plenty of open space for other activities.

Adjacent to the park is a community swim center. It didn't seem to be the typical center; It had several adults doing laps.

After lunch, we visited the rock shop that is near the edge of Moab. There were all sorts of interesting rocks. The three-year old picked up several rocks including some that were quite valuable. He was instructed to put one back, so from about ten feet away, he found the right pile where he got it from and threw the rock back into its proper pile. We learned at the store that there is an area beyond Potash (about 20 miles from Moab) where many of the store's collectables are picked up.

We journeyed out this way before it started to get dark. On the way, there are dinosaur prints that can be examined from the road along the Colorado River. The prints are high up on a vertical slab of rock. They are white on a dark slab so they are quite visible. By the time, we hit the end of the road beyond Potash, we had to turn back because the road was bad and it was getting dark.

Tags: , , , , ,

Moab | Vacation

In The ‘Hood

by Bryan Sever 4/9/2009 10:58:25 AM

April 9, 2009 - Nearby in a field where we are staying in the Moab neighborhoods, there is a flock of wild turkeys. A few of us (2 adults, 2 children) went to get up close.

As we approached the turkeys, we called out in turkey language hoping for a response. However, they slowly moved away from us as we approached and found their way into the brush.

However, the journey was not without merit. The children were able to see what turkey tracks look like. They also seen the fresh droppings. Nearby where the turkeys had retreated into the brush, we found a deer skeleton and bones.

Tags: , ,

Vacation | Moab