Solved

.net Date Class creates wrong dates?????

Posted on 2004-10-08
7
266 Views
Last Modified: 2010-08-05
Hello,

Anybody knows why when i create a date using "new Date(2004, 10, 1)" it returns "01-01-0001"
i've tried with another dates and the same result.


Thx in advance,

Hugo
0
Comment
Question by:lima_hugo
7 Comments
 
LVL 11

Expert Comment

by:pratap_r
ID: 12257403
are you sure?

this is the code in VB.Net

        Dim d As new Date(2004, 10, 1)
        MsgBox(d.ToString())

it shows -> 10/1/2004 12:00:00 AM

and for C#.net

      DateTime d=new DateTime(2004,10,1);
      MessageBox.Show(d.ToString());

yeilds the same result

can you post your code? may be theres some problem somewhere else

Enjoy!
Pratap
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 12257423
There is surely something else. I just tested it ok with this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dt As Date = New Date(2004, 10, 1)
    MessageBox.Show(dt)
End Sub

Can you show your own code?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 12257429
pratap_r, your comment was not there before I started testing it!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:pratap_r
ID: 12257447
no problem emoreau :) well atleast we are in sync :-)
0
 

Author Comment

by:lima_hugo
ID: 12257514
Sorry, i forgot to mencion that i executed that code in the debug imediate window in a asp.net application, in there the comand "?new date(2004,1,1).ToString" returns "01-01-0001"
but i didn't tested it in runtime.

Now i've tried your code and it works, but in the imediate window doesn't, maybe because it can't allocate new objects??
0
 
LVL 3

Accepted Solution

by:
yellowjetski earned 125 total points
ID: 12258587
The immediate widnow is used when debugging an application for evaluating expressions, print variable values, or execute statements. It can also be used to change the value of a variable during debug or even to execute a function or statement.

It CANNOT make new variables. That's why the default date is showing when to try to get the output (01-01-0001)
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12258683
it actually sets the object to nothing if you try it. for example if you have a variable declared as date, using immediate window to set it to a new object actually sets the variable to nothing, there by defaulting to the value #1/1/0001#

the scope again is the current executing code
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 67
python question 5 69
listing all functions in JavaScript 19 172
Device same like our heart 12 73
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now