Question DateTime.Today is giving January 1, 2000

JeffKan1

New member
Joined
Jun 10, 2015
Messages
3
Programming Experience
10+
Hello everyone, first-time poster here. My system date on my computer looks correct, June 10, 2015. I have a class file that has the following code:

C#:
DateTime thisday = DateTime.Today;

When I display the results by a Console.Writeline() command of thisday.ToString(), it shows:

01/01/2000 00:00:00

... which is January 1, 2000.

Any ideas?

Thanks!

Jeff
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,130
Location
Sydney, Australia
Programming Experience
10+
That's obviously not normal so either there's a bug in your code or something on your system is broken. It's really not something that we can diagnose from the information provided. My guess would be that it's a bug in your code.

Firstly, is that a field or local variable? Secondly, how EXACTLY is it being accessed?
 

JeffKan1

New member
Joined
Jun 10, 2015
Messages
3
Programming Experience
10+
It's a local variable. I'm a developer of 20+ years, but my experience with C# is small, so patience is requested. :apple:

The above line of code is in an instance method, public void. The method is in a helper class. I assume "using System" gets me all the needed classes and methods. Code builds without error. The application is for a label printer by Intermec.

Version of Visual Studio is 2013, 12.0.110100 Update 4. Computer is Win 7 Pro SP 1.

DateTime.Today seems to be such a straight-forward static, that I'm at a loss as to what could be wrong. Could this be related somehow to the lack of specifying a CultureInfo object? I am in the U.S. of course.

In my research, I read somewhere about an "epoch" that starts Jan 1 2000, but I can't seem to find it again. This is definitely a strange issue!

For how it's being accessed, my goal is to build a date format of yyMMdd, for example June 11 would be "150611". Just trying to grab the current date and set it up. The Writeline shows thisDay.ToString(), and my research showed the default format is "G" for the overridden DateTime.ToString().
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,130
Location
Sydney, Australia
Programming Experience
10+
I would recommend placing a breakpoint on that line. When execution breaks, use the Watch or Immediate window to evaluate both DateTime.Today and `thisday`. Hit F10 to step to the next line and then evaluate again. Let us know what you see.
 

JeffKan1

New member
Joined
Jun 10, 2015
Messages
3
Programming Experience
10+
Yes, excellent suggestion. I believe I have an answer... it's the environment from which the code is run.

Taking your suggestion, I commented out code for the Intermec printer, and put in a breakpoint and ran the code. All is good, DateTime.Today is the correct date, today's date. Everything from there is fine.

Build the code, send it to the Intermec printer, and run the code from there: DateTime.Today is Jan 1 of 2000. So the problem is that the Intermec Printer doesn't know what today's date is. I will move forward and focus on fixing THAT issue.

Thanks jmcilhinney!
 
Top Bottom