Converting strings to DateTime structs
-
I get dates in the following format: Mar-07 13:45 How can I feed this to a ConvertTo.DateTime expression without getting an exception? Sammy "A good friend, is like a good book: the inside is better than the cover..."
-
I get dates in the following format: Mar-07 13:45 How can I feed this to a ConvertTo.DateTime expression without getting an exception? Sammy "A good friend, is like a good book: the inside is better than the cover..."
Tough luck. I think you need to write your own function to read it and convert it to ISO format. Check if the format is always mmm-dd hh:nn. If it is, it will be simpler for you to write the function. I might be wrong though, so if anyone knows about this, feel free to answer. :) Edbert P. Sydney, Australia.
-
Tough luck. I think you need to write your own function to read it and convert it to ISO format. Check if the format is always mmm-dd hh:nn. If it is, it will be simpler for you to write the function. I might be wrong though, so if anyone knows about this, feel free to answer. :) Edbert P. Sydney, Australia.
Yes in fact, it is always in this format. How should I write this function? Sammy "A good friend, is like a good book: the inside is better than the cover..."
-
Yes in fact, it is always in this format. How should I write this function? Sammy "A good friend, is like a good book: the inside is better than the cover..."
I've checked that in your case you only need to add the year value to the string. Here's what I would do:
string dateValue = "Mar-07 13:45";
string[] dateParts = dateValue.Split(' ');
dateValue = String.Concat(dateParts[0], "-", DateTime.Now.Year, " ", dateParts[1]);You can use the final string as input for any DateTime functions. Edbert P. Sydney, Australia.
-
I've checked that in your case you only need to add the year value to the string. Here's what I would do:
string dateValue = "Mar-07 13:45";
string[] dateParts = dateValue.Split(' ');
dateValue = String.Concat(dateParts[0], "-", DateTime.Now.Year, " ", dateParts[1]);You can use the final string as input for any DateTime functions. Edbert P. Sydney, Australia.
A word of warning when reading December's data in January - it may have wrong year! Remember to add logic something like pseudocode: if(Month(data) > Month(Now)) DataYear -= 1; Regards Brewman