For each only working on last item in list<string>

Hi there,

I have a list of string called dates, which is instantiated with new List(of String) from {“01/02/1999”,“04/05/1985”,“05/05/1999”}.
I would like to convert this list of strings to DateTime variable type, hence I first created a new variable called newdates with DateTime variable type.
I then used the For each activity, inside the activity I used assign activity and did To as newdates and Value as DateTime.Parse(item)
After that I printed the new dates out using log message by typing newdates as message.
However, only the last item which is 05/05/1999 00:00:00 was printed out but not the other two dates.
Is there any reason why the for each is not working? I thought after the for each activity is performed, newdates will be stored with a list of dates in DateTime variable type, hence the printing should work

Thanks.

Hi, where is located the log message activity? Based on your explanation I think you are overwriting the newdates variable, so if the log message is outside the For each activity you will get the last value of newdates, which is actually the last item of the list.

Anyway, you can try this in order to convert all the items of a list of strings to a list of datetime items:

listStringDates.Select(Function (x) Datetime.ParseExact(x, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)).ToList()

I hope this help.