Solved

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

Posted on 2004-10-08
7
267 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 70

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 70

Expert Comment

by:Éric Moreau
ID: 12257429
pratap_r, your comment was not there before I started testing it!
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordmultiple challenge 12 131
Rubik's Cube Code for Effective Presentation 3 52
I need an assist with a programming logic math question. 5 64
Android development question 2 34
A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

786 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