Wednesday, April 1, 2009

Using your computers date for the sleep calculator

I had someone post a comment the other day asking how the "rather silly sleep calculator" could use the current date according to the computer to make it's calculation. First of all, let me say that I'm scared, I didn't mean to get readers :-). Secondly, it's really cool that any of them take the time to comment let alone read anything I post.

Anyway, I want to point out straight off that my program probably wouldn't work as is with the computers own date. The reason for this is that the program (as I wrote in the original post on the sleep calculator) uses short years and months. You will lose 5 days in a normal year (6 in a leap year), lose 1 day for seven months each year and gain 2 days for one month (except in a leap year when you only gain 1 day for that month). No, to make this workable, a whole new equation will need to be worked out.

Having said all of that, I did some digging and found that you can use the Now() function to use the computers date. I get the distinct impression that this function is for older versions of VB. I can tell you that in Visual Studio, it comes up black.

A reader by the name of Jack posted this comment:
My.Computer.Clock.LocalTime.Year
this is the code that shows the year from your computer system, and you can try the month and the day as the same.
which would make sense (however, it was posted on April 1st local time...), but you would still need to store the result in a variable obviously.

I also found a pretty cool site called Top54u that showed how to display the date in various formats once you've captured it. I'd love to look into this further and redevelop the "rather silly sleep calculator" into an awesome and actually usable sleep calculator. I have the next two weeks off class, so I might give that a shot during the "break" (a term used very loosely as I have HEAPS of work to catch up on in the time).

Anyway, I hope there has been some helpful stuff in here and thanks to everyone who has been reading and keep the comments coming.

All the best,

Tim.