Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date to string and conversion

Status
Not open for further replies.

chapm4

IS-IT--Management
Nov 12, 2001
38
0
0
US
Hi,
I have a text box that I have displaying the date in short form 2 months ago
aDate = Now
aDate = aDate.AddMonths(-2)
TextBox1.Text = aDate.ToShortDateString
I then want to take that short date yy/mm/dd and convert it to a string that looks like yymmdd for file deletion. Can't figure out the format string.
 
Thanks for all the help the last few day's BTW.

I have seen the link. I just can't get the code right. Here is what I have:

Dim fName As String
Dim bDate As String
aDate = Now
aDate = aDate.AddMonths(-2)
aDate = aDate.ToShortDateString(yyMMdd)

ToShortDateString has no parameters and it's return type cannot be indexed.

The deal is I have files that need to be deleted but their name looks like: auth.020730
 
That works great thanks! So simple even.

One more question. If I want do delete every day's files previous to that date, how is that done?

For instance the date is 06/01/02 so the file name is auth.060102 The above works great for that file, but I want to delete others such as auth.053002, auth.0529.02......etc.

I think I owe you a beer or something.
 
If you are looping through all the files to check for deletion candidates then in a temporary variable reformat the the filename so it turns into a date.

In theory you would take the file name (auth.0529.02)(auth.053002) and copy the name to a temp variable. Then loop though each character and see if it is a number, if not then remove that character. That should leave you with (052902)(053002) then (assuming all are 4 digits) add the &quot;/&quot;'s in the right places and convert (CDate) to a date to check if > or < or = so you know if you can delete that file. (This seems to me like a bad way to do it, but it is the only thing that is comming to mind.)

Another thought, is there any way to access the created date of the file from the OS? If so then you may not need to do all this work. I copied the following line from the help files, it says you should be able to access the created date and last modified date so you might want to try that instead. &quot;The FSO model gives your application the ability to create, alter, move, and delete folders, or to determine if and where particular folders exist. It also enables you to get information about folders, such as their names and the date they were created or last modified.&quot;

Instead of a Beer, a Start would be nice.

Kris
[r2d2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top