Fun with DateTime

November 17th, 2008

The results of my messing around with .NET DateTime. Hope this is useful for someone else!

using System;
namespace ConsoleApplication1
{
   class Program
   {
      static void Main(string[] args)
      {
      // fun with DateTime
      // right now, including the time
      Console.WriteLine(DateTime.Now);

      // today's date, no time (midnite)
      Console.WriteLine(DateTime.Today);

      // stripping a time off a DateTime (so it's midnite, useful for database queries)
      DateTime startDate = DateTime.Parse("10/31/2008 5:25 pm"); // pretend this came from a database or something
      Console.WriteLine(startDate); // see the time displayed
      startDate = startDate.Date; // this is just the date portion with no time
      Console.WriteLine(startDate); // see, just has the date now

      // difference, in number of days, between two dates, human-logic, that is, the 5th is 2 days after the 3rd, no matter what time it was
      DateTime endDate = DateTime.Parse("11/03/2008 4:25 pm"); // pretend this came from a database or something, too
      int days = (startDate.Date - endDate.Date).Duration().Days; // absolute value, order of start and end dates is not important
      Console.WriteLine(days);
      int days2 = (startDate.Date - endDate.Date).Days; // real value, order of start and end dates IS important
      Console.WriteLine(days2);

      // difference between dates with time portion, such as .25 hours (time and attendance, payroll)
      startDate = DateTime.Parse("11/17/2008 8:00 am");
      endDate = DateTime.Parse("11/17/2008 4:45 pm");
      TimeSpan interval = endDate - startDate; // order matters
      Console.WriteLine(interval);

      // hey, don't we get a lunch break?
      DateTime startLunch = DateTime.Parse("11/17/2008 12:00 pm");
      DateTime endLunch = DateTime.Parse("11/17/2008 12:25 pm");
      TimeSpan lunchInterval = endLunch - startLunch; 
      Console.WriteLine(interval - lunchInterval); // 20 minutes of overtime! (yeah, right)

      Console.Read();
      }
   }
}

Don’t blame me, blame Excel

November 15th, 2008

I found this recent news item over on Computer World pretty amusing.

Excel error leaves Barclays with more Lehman assets than it bargained for

October 14, 2008 (Computerworld) A reformatting error in an Excel spreadsheet has cropped up in the largest bankruptcy case in U.S. history, prompting a legal motion by Barclays Capital Inc. to amend its deal to buy some of the assets of Lehman Brothers Holdings Inc.

one of its first-year law associates had unknowingly added the contracts when reformatting a spreadsheet in Excel.

Going on to read the rest of the article, it seems the real error here was that someone was in a hurry and didn’t pay enough attention to what he was doing. He was trying to export contents of Excel to a PDF.

However, contracts that had been marked as “hidden” in the spreadsheet when it was received by the law firm were added to the purchase offer during the reformatting process, according to the motion. Those contracts weren’t supposed to be part of the deal; they also were marked with an “N” for “No” in the original version of the spreadsheet, Cleary Gottlieb said in the motion.

That doesn’t seem like a “reformatting” error to me. That seems like an ID1OT error. We all do dumb things when we’re rushing to complete a task. That’s why I try very hard NOT to be in a hurry. It just leads to screw-ups. In this poor guy’s case, though, his mistake was very costly to both him and his company.

I have made some mistakes when rushing that have taught me the extreme value of simply taking that extra time to proof-read, and to breathe. I’ve used the wrong set of primary keys to update a database. I’ve forgotten a very crucial piece of a where clause. These mistakes have taught me to step back, take a little extra time, and don’t stress, or I might be spending a lot MORE time cleaning up my mess.

What’s the biggest mistake you’ve made when you’re trying to rush to complete a task? What did it teach you? Did you take responsibility, or try to blame the tools you used? How did it work out for you?

I AM smiling [funny pic]

November 8th, 2008

funny dog pictures with captions
see more puppies

Political humor [video]

November 8th, 2008

I can’t believe I just saw this today. Obama vs McCain, Republican view vs Democratic. Highly amusing.

Which path shall the young man take?

November 6th, 2008

[From Bits and Pieces]

An old country preacher had a teenage son, and it was getting time the boy should give some thought to choosing a profession. Like many young men his age, the boy didn’t really know what he wanted to do, and he didn’t seem too concerned about it. One day, while the boy was away at school, his father decided to try an experiment. He went into the boy’s room and placed on his study table four objects.

1. A bible.

2. A silver dollar.

3. A bottle of whiskey.

4. And a Playboy magazine.

“I’ll just hide behind the door”, the old preacher said to himself. “When he comes home from school today, I’ll see which object he picks up.

If it’s the bible, he’s going to be a preacher like me, and what a blessing that would be! If he picks up the dollar, he’s going to be a business man, and that would be okay, too. But if he picks up the bottle, he’s going to be a no-good drunken bum, and Lord, what a shame that would be. And worst of all if he picks up that magazine he’s going to be a skirt-chasing womanizer.”
The old man waited anxiously, and soon heard his son’s foot-steps as he entered the house whistling and headed for his room.

The boy tossed his books on the bed, and as he turned to leave the room he spotted the objects on the table. With curiosity in his eye, he walked over to inspect them.

Finally, he picked up the Bible and placed it under his arm. He picked up the silver dollar and dropped into his pocket. He uncorked the bottle and took a big drink, while he admired this month’s centerfold.

“Lord have mercy!”, the old preacher whispered disgustedly .. “He’s gonna run for Congress!”