0

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

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by campkev
0

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);
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.