Hi

I got diffrent date formats from a database and I would like to convert the to a date. I don't have the option to work with the sql, since that query is fixed (long story)

"20051231","2005-12-31","2005-12-31 09:29:52" ==> "2005/12/31".

My first tought was to trim the string and remove "/" and " ", after that only read the first 6 char of the string and as the final step chope the string up in "2005","12","31". There after build upp "2005/12/31".

It seems to by much work and not so easy either as I tought.

Does anyone have any advice in thos matter.

/Matt

have you tried DateTime.Parse ?

if you are sure those are the only 3 formats the date will be in, you can do this:

string strDate;

//pseudocode
// strDate = date from database

if(strDate.Length>8)
				strDate= strDate.Substring(0,10).Replace("-","/");
			else
				strDate= strDate.Substring(0,4)+"/"+strDate.Substring(4,2)+"/"+strDate.Substring(6);

whoops, yeah i was thinking you wanted a string. If you want a datetime, go with first reply.