Solved

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

Posted on 2004-10-08
7
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hive vs Impla in Hadoop 1 81
AvlTree-Node Data type 4 26
Mutiple Folder view (5 Folder view) 3 54
How to delete text box content on subform 1 20
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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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