Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a string "1957-08-27 12:00:00.000"
I want to convert this to Dateandtime of format 27/08/1957 (Time part is not required).
How do I do this?
Posted

Start with the DateTime.TryParse()[^] method, or any of the other Parse() methods.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Apr-12 12:26pm    
And nothing more; a 5.
--SA
Richard MacCutchan 25-Apr-12 12:30pm    
Given that the OP knows they want a DateTime conversion, I wonder why they cannot go and read the documentation in the first place. It seems to me we are creating a generation of programmers who cannot do much beyond copy and paste, drag and drop, and beg for help on CodeProject. Let's hope none of them work for my bank. end of rant.
Sergey Alexandrovich Kryukov 25-Apr-12 16:11pm    
So true!
--SA
Analysis of the feasibility of asking the above Question?

In the body of the questions there are 122 characters (without any spaces),

(Assume)
If each character take .1 seconds to type so that will come up .1x122=12.2 seconds.

The question itself 26 characters (without any spaces) so that will be .1x26 = 2.6 seconds.

And Depending the internet speed and familiarity of the Codeproject’s ask a questions section, I would assume it will take another 1 mins to submit the questions (OP).

On top using the based assumption (without using any prediction or learning algorithm for calculating the time frequency) of the Codeproject’s question answer time frequency I would assume it will take another (at least) 5 mins to get a answer back.

So it comes up al together 5mins + 12.2 seconds + 2.6 seconds = 5mins 14.8 seconds.

Where as while I type the question in the www.google.com[^] website it will come up the 12,900,000 results within .39 seconds (depending on my internet speed)

Still I would believe this will save OP’s lots of time and as well as improve their research skills to find out the solution for a problem.
 
Share this answer
 
Comments
VJ Reddy 25-Apr-12 23:42pm    
Innovative Analysis. 5!
Mohammad A Rahman 25-Apr-12 23:48pm    
Thank you VJ :)
V G S Naidu A 26-Apr-12 0:02am    
exactly you are right Mr.Mohamad.
Mohammad A Rahman 26-Apr-12 1:01am    
:)
If You are getting Date From Database You can use the above Query in stored procedure

This link Wil give You More Info About Date Time Formatting...
http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx[^]
or You can use this ShorDateTime Function
C#
string to_date2;
to_date2 = DateTime.Now.ToShortDateString();
DateTime today;
today = DateTime.Parse(to_date2);
string to_day;
to_day = today.ToString(("yyyy-MM-dd"));
 
Share this answer
 
v2
Hi,

Just try this:

C#
string oldFormat="1957-08-27 12:00:00.000";
            string newFormat = Convert.ToDateTime(oldFormat).ToString("dd/MM/yyyy");
 
Share this answer
 
try this..

C#
string.Format(string, "dd/mmm/yyyy")
string.Format("{0:dd/MM/yyyy}",string)
 
Share this answer
 
v2
 
Share this answer
 
Try this:
SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900