Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2005

Tip: Looking for answers? Try searching our database.

Problem with datetime constructor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Trapulo - 25 Jan 2005 18:09 GMT
Why this?

>? new DateTime(2005, 1, 1).tostring
"01/01/0001 0.00.00"

I think the right output is "01/01/2005 0.00.00"...

I've some tests on a property set routine, as

If Value > New DateTime(2025, 1, 1) Then Throw New
ArgumentOutOfRangeException("registrationDateTime must be before gen 1, 2025")

and I cannot make work them!

thanks
Jon Skeet [C# MVP] - 25 Jan 2005 20:41 GMT
> Why this?
>
> >? new DateTime(2005, 1, 1).tostring
> "01/01/0001 0.00.00"
>
> I think the right output is "01/01/2005 0.00.00"...

And that's the output on my box.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Trapulo - 26 Jan 2005 11:13 GMT
> > Why this?
> >
[quoted text clipped - 4 lines]
>
> And that's the output on my box.

:(((((

> Could you post a short but complete program which demonstrates the
> problem?

This is not simple, because the code is inside a buiness object used in a
3-tiers web-based application.

This is the property:
Public Property RegistrationDateTime() As DateTime
       Get
           Return _registrationDateTime
       End Get
       Set(ByVal Value As DateTime)

           If Value = Nothing Then Throw New
ArgumentNullException("RegistrationDateTime")
           If Value < New DateTime(2005, 1, 1) Then Throw New
ArgumentOutOfRangeException("registrationDateTime must be after gen, 1 2005")
           If Value > New DateTime(2025, 1, 1) Then Throw New
ArgumentOutOfRangeException("registrationDateTime must be before gen, 1 2025")

           _registrationDateTime = Value

           Me.MarkAsModified()

       End Set
   End Property

Because value is  #1/15/2004# I've an error on the second test. If I execute
on command window the code I previously posted, I've the wrong output. It
seems I've some very very strange problem with datetime behavior..

thanks
PIEBALD - 26 Jan 2005 16:05 GMT
Only problem I see is that when I tried it with C#, the compiler told me that
I can't compare the DateTime value with null (nothing).

If yours compiles, then I don't know.
Trapulo - 26 Jan 2005 18:19 GMT
In VB I can (if I use = and not "IS" of course)

> Only problem I see is that when I tried it with C#, the compiler told me that
> I can't compare the DateTime value with null (nothing).
>
> If yours compiles, then I don't know.
Jon Skeet [C# MVP] - 26 Jan 2005 17:11 GMT
> > Could you post a short but complete program which demonstrates the
> > problem?
>
> This is not simple, because the code is inside a buiness object used in a
> 3-tiers web-based application.

So take the code out of the business object, and try to show the
problem in a console app.

I can't see anything in your code which would stop it from being part
of a simple console app...

<snip>

> Because value is  #1/15/2004# I've an error on the second test. If I execute
> on command window the code I previously posted, I've the wrong output. It
> seems I've some very very strange problem with datetime behavior..

I'd avoid using the command window for this kind of thing - try to
reproduce it in a standalone way which doesn't involve the debugger.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Trapulo - 26 Jan 2005 18:23 GMT
Oh my GOD!

I solved, and you are right.

The problem was a stupid error with data value. The error was raised by the
FIRST test, but the VS debugger reported the yellow-background line on the
second. So I was thinking the problem was on the second, but was on the
first test.

Anyway, the command window has this strange and wrong behavior. It reports a
bad value with my quick-test command, so I think there is some bug. At
runtime is all ok.

Thanks!

> > Because value is  #1/15/2004# I've an error on the second test. If I execute
> > on command window the code I previously posted, I've the wrong output. It
> > seems I've some very very strange problem with datetime behavior..
>
> I'd avoid using the command window for this kind of thing - try to
> reproduce it in a standalone way which doesn't involve the debugger.
Jay B. Harlow [MVP - Outlook] - 27 Jan 2005 22:37 GMT
Trapulo,
In addition to the other comments.

>> > >? new DateTime(2005, 1, 1).tostring
>> > "01/01/0001 0.00.00"
> on command window the code I previously posted, I've the wrong output. It

Seems to be one of many limitations of the Command Window, If you try the
code in VB.NET it performs as expected.

I would recommend you change to function to include the "value" parameter as
part of the exceptions,
allowing you can see exactly what the value of "value" is when it fails.

Something like:

   Public Property RegistrationDateTime() As DateTime
       Get
           Return _registrationDateTime
       End Get
       Set(ByVal value As DateTime)

           If value = Nothing Then Throw New ArgumentNullException("value",
"RegistrationDateTime")
           If value < New DateTime(2005, 1, 1) Then Throw New
ArgumentOutOfRangeException("value", value, "registrationDateTime must be
after gen, 1 2005")
           If value > New DateTime(2025, 1, 1) Then Throw New
ArgumentOutOfRangeException("value", value, "registrationDateTime must be
before gen, 1 2025")

           _registrationDateTime = value

       End Set
   End Property

Hope this helps
Jay

>> > Why this?
>> >
[quoted text clipped - 42 lines]
>
> thanks
Trapulo - 30 Jan 2005 11:13 GMT
Thanks for your suggestion!

> Trapulo,
> In addition to the other comments.
[quoted text clipped - 81 lines]
> >
> > thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.