DateTime format problem

Posted on 2008-11-17
Medium Priority
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
  • 2
  • 2
LVL 14

Expert Comment

ID: 22974656
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

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

Accepted Solution

Binuth earned 2000 total points
ID: 22974725

//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

ID: 22974903
Hi Binuth:
Understand now, works OK thanks

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

807 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