views:

34

answers:

2

Hi Guys,

I am making an SQL Query that brings back a list of files and their paths. They have different file paths and different file names ofc.

The file names are dates and time in the form of YearMonthDayHourMinuteSeconds.

What I need to do is take the filepath that thas the latest date and time, strip off everything except the date and time part and then using the date and time requery the database.

I have very few ideas on how to do this.

EDIT: The date will be chagning and I need to take the latest when ever the program is run.

Thanks,

A: 

use the standard .NET file operation libraries

something like:

using System.IO;
...
string myFileNameWithFullPath;
...
DateTime newDate = DateTime.Parse(Path.GetFileName(myFileNameWithFullPath));
Jonny Cundall
This would assume, that the file name would be the same everytime? Added an edit to my post.
Vibralux
I don't think it makes any such assumption. I haven't given you the line where you assign the string each time, because I don't know how you're getting it - there's lots of ways of running an SQL query in c#
Jonny Cundall
A: 

My first idea would be to treat everything the query returns as strings

When you get your result set, you could iterate through it storing the record you want in a string or multiple strings. You can compare strings with firststring.Compare(secondstring) it returns 1 or greater if the secondstring is alfabeticaly after firststring.

Then use substring to extract the part of the string you want

string inf = latestdate.Substring(startindex, length);

Hope this helps

Constantin