?
Solved

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

Posted on 2004-10-08
7
Medium Priority
?
272 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
Industry Leaders: 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 375 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

A short article about problems I had with the new location API and permissions in Marshmallow
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

649 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