Groups | Blog | Home
all groups > asp.net webcontrols > november 2006 >

asp.net webcontrols : difficulty setting time values in Calendar


Beemer Biker
11/15/2006 5:31:22 PM
Observation:
I am using the dotnet calendar to set a date and time field. I added
hours and minutes fields to my popup since there is no time picker
available. http://stateson.net/pub/cal1.jpg I see no method to set items
like hours, minutes, seconds. Instead there are functions to add hours,
minutes and seconds. So if the user changes the drop down list, say from
november to october, I have to calculate 10-11 = -1 and then use
Calendar1.SelectedDate = Calendar1.SelectedDate.AddMonths(-1); This gets
very awkard for hours minutes and seconds. It appears there is no way to
directly assign fractions of date and time.

Question:
I see where there is a 64 bit value available that (this is from
intellisense) "serializes the current date time object to a 64 bit value
that can subsequently be used to initialize a datetime object).

OK. So I got it using .ToBinary() and stored it in an int64. then I fondle
the value and want to put it back. How do I do that?
I tried the following and it wont compile:
Int64 bigVal = Calendar1.SelectedDate.ToBinary();
bigVal += 1;
Calendar1.SelectedDate = (Int64) bigVal;

cannot convert long to System.DateTime

with or without the cast I still have a "long" problem. I also tried "long
long" and VS8 did not like that.

MikeS
11/16/2006 3:39:13 PM
How about DateTime.FromBinary?
MikeS
11/17/2006 8:46:06 AM
Ya, if you do that in Visual Beginner's All-purpose Symbolic
Instruction Code .NET, the IDE gives you a smart tag for the Error
Corrections Options (Shift+Alt+F10) dialog pointing out the error with
a suggestion for the fix that it will put in place in the code
automatically. Apparently beginners need the extra help.
Beemer Biker
11/17/2006 9:09:02 AM
[quoted text, click to view]

Thanks Mike.

When you mentioned FromBinary, I didnt recall seeing that member when I was
coding it up. I brought my C# dotnet project back up and intellisense shows
no member with that name. It does show ToBinary which I had discovered
earlier. OK I then highlighed DateTime and hit F1 and sure enough there is
a member: FromBinary. It seems not to show up in intellisense because it
cannot be used as an instance.

I tried a number of things and was unable to compile. At a minimum I
thought this should have worked:

DateTime dt = DateTime.Now;
dt = dt.FromBinary(dt.ToBinary());

static member 'System.DateTime.FromBinary(long)' cannot be accessed with an
instance reference; qualify it with a type name instead

OK, i then tried the following which worked:

DateTime dt = DateTime.Now;
Int64 BigOne = dt.ToBinary();
DateTime dateFromNumber = DateTime.FromBinary(BigOne);

In fact, as soon as I typed "DateTime." intellisense presented FromBinary as
a choice. That was missing when I originally typed "dt."

so today I learned what this means: "static member xxx cannot be accessed
with an instance reference; qualify it with a type name instead "


--
=======================================================================
Beemer Biker joestateson at grandecom dot net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================

AddThis Social Bookmark Button