Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

c# DateTime outputting Monday, 01 January 0001

  • 16-07-2006 08: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