DateTime format problem

Posted on 2008-11-17
Last Modified: 2013-12-17
Can anyone help with this datetime problem.
In my BLL i have: this.travelNewsDateInserted = Convert.ToDateTime(travelNewsDateInserted.ToString("ddd dd MMM yyyy HH:mm:ss")); which should return something like: Sun 16 Nov 2008 19:15:36

But what i'm getting is: 16/11/2008 19:15:00

In my aspx.cs file i have:
  List<RetrieveTravelNewsObj> returnTravelNews = getTravelNews.GetTravelNews(strDisplayMode, strDisplayFullNewsDetails);
            if (returnTravelNews.Count > 0)
                foreach (RetrieveTravelNewsObj DisplayTravelNews in returnTravelNews)
                    TravelNewsDateInserted.Append(DisplayTravelNews.TravelNewsDateInserted.ToString("ddd dd MMM yyyy HH:mm:ss"));

I have even added ("ddd dd MMM yyyy HH:mm:ss")); to the aspx.cs file but i just cannot change the date format.

Any help would be appreciated
Question by:BeginningWebDesign
    LVL 14

    Expert Comment

    this.travelNewsDateInserted = Convert.ToDateTime(travelNewsDateInserted.ToString("ddd dd MMM yyyy HH:mm:ss"));

    here you are trying to store formatted datetime string to DATETIME Datatype( i.e this.travelNewsDateInserted). datetime data type never store date somthing like "Sun 16 Nov 2008 19:15:36" , if you want to keep same format use STRING Datatype insteed of DATETIME Datatype

    Author Comment

    Hi Binuth:
    I'm not sure what you mean, can you give me a example
    LVL 14

    Accepted Solution


    //DateTime Datatype : internaly it stores only digit like year month day
    			DateTime travelNewsDateInserted = new DateTime(2008,10,10);
    			// here you trying to store same DATETIME, i.e when you use Convert.ToDateTime - function it returns
    			// DATETIME object not formated string object
    			travelNewsDateInserted = Convert.ToDateTime(travelNewsDateInserted.ToString("ddd dd MMM yyyy HH:mm:ss"));
    			String strTravelNewsDateInserted; 
    			//Here STRING Datatype : you can store formated string
    			strTravelNewsDateInserted =  travelNewsDateInserted.ToString("ddd dd MMM yyyy HH:mm:ss");

    Open in new window


    Author Comment

    Hi Binuth:
    Understand now, works OK thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now