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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

c# DateTime outputting Monday, 01 January 0001

  • 16-07-2006 7:41pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 872 ✭✭✭grahamor


    thanks a million, that worked perfectly.


Advertisement