I have the following code:
static void Main(string args)
foreach (string elem in Directory.GetFiles(@"C:\Users\A\Desktop\FIles", "*.txt"))
StreamReader reader = new StreamReader(elem);
Console.WriteLine(DateTime.ParseExact("5/10/2005", "m/d/yyyy", null).Day);
What i need is to select only the Date from a file.
For example if i have the string "the date is 20/2/2012" in a
.txt file, i need to substract only
20/2/2012 and to compare it with the current date.
If you want an easy lazy solution, you can always add a
: and Split on it. (You could split on white spaces but then I would have to count for the index and I don't want to do this).
string dateFromFile = "The date is : 20/2/2012"; string dateString = dateFromFile.Split(':'); string myDate = dateString;
Ok I looked at my answer and decided I was too lazy...
string dateFromFile = "The date is 20/2/2012"; string dateString = dateFromFile.Split(' '); string myDate = dateString;
It splits the string everytime it sees the sepcified character and returns a
In the second example (where I split on white space, the array would look like this)
dateString = "The" dateString = "date" dateString = "is" dateString = "20/2/2012"