Solved

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

Posted on 2004-10-08
7
265 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
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…
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 …
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now