Convert an array of DateTime values to a string and back again


	//CONVERT ARRAY OF DATE TIME TO COMMA SEPARATED STRING
	array<DateTime> ^MyDateTimeArray;
	String ^MyString;

	MyString = "";
	for (Count = 0; Count < MyDateTimeArray->Length; Count++)
		MyString += MyDateTimeArray[Count].ToString("yyyy-MM-ddTHH:mm:ss.fffffff") + ",";

 


	//CONVERT COMMA SEPARATED STRING BACK TO ARRAY OF DATE TIME
	String ^sTemp;
	while (1)
	{
		//GET THE NEXT DATATIME VALUE (they are comma seperated and there is always a trailing comma)
		if (MyString->LastIndexOf(",") <= 0)
			break;
		sTemp = MyString->Substring(0, (MyString->IndexOf(",")-1) );
		MyString = MyString->Substring( (MyString->IndexOf(",")+1) );

		Array::Resize(MyDateTimeArray, (MyDateTimeArray->Length + 1));
		MyDateTimeArray[(MyDateTimeArray->Length - 1)] = Convert::ToDateTime(sTemp);
	}

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.