Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c# DateTime outputting Monday, 01 January 0001

Options
  • 16-07-2006 8:41pm
    #1
    Registered Users Posts: 872 ✭✭✭


    Hi i am using the DateTime class to output the date in the following format

    Day, date month year.

    I am using DateTime dt and dt.day etc.

    For some reason it is outputting as Monday, 01 January 0001 and i cant figure out why, i thought it got the time from the server it was on.

    Any ideas ?

    Thanks


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    I suspect your doing this:
    DateTime dt = new DateTime();
    
    Which is creating a blank DateTime, the values default to the values you're seeing.

    You need to do something like this:
    [color=red]DateTime dt = DateTime.Now;[/color]
    string currentDate = dt.DayOfWeek.ToString() + ", " + dt.ToLongDateString(); 
    
    The static property DateTime.Now will initialise your DateTime variable with todays date and time. This will come from the local machine so when you upload to the server you'll get the servers current date and time.


  • Registered Users Posts: 872 ✭✭✭grahamor


    thanks a million, that worked perfectly.


Advertisement