Adding date on filename

Nov 6, 2010 at 3:47 AM

Newbie VB learner here. Sorry for the easy question.

How can I add dates to the zip files name?

I know it has to be something in here:"")

Thanks in advance.

Nov 6, 2010 at 10:21 AM

Well, sure.  If you want the zipfile to have a specific name, then use that specific name when calling zip.Save("")

maybe you are really asking, how can I format a string with the current date.  In that case, what you want is something like this:

Dim filename as String
filename = String.Format("BaseName-{0}.zip", DateTime.Now.ToString("YYMMDD"))

Read the reference documentation on DateTime for more details.


Nov 7, 2010 at 8:23 PM

Thanks for the tips. I tried your code but resulting file name shows up as ""

I tried to search "DateTime" in the reference documentation but the closest that I can find is at Reference -> -> ZipEntry -> SetEntryTimes(DateTime, Datetime, Datetime)

Is that what you are referring to?

Nov 7, 2010 at 8:53 PM

whoops - convert that code to this:

filename = String.Format("BaseName-{0}.zip", DateTime.Now.ToString("yyyyMMdd"))

(case is significant).

You asked about SetEntryTimes().... No, that's not what I was referring to.  I was referring to the System.DateTime structure - part of the class library that is built-in to .NET.   This structure provides a way to get the current time (DateTime.Now) and also a way to convert the DateTime value to a string (DateTime.ToString()).   Combining those gets you what you want.

Regarding SetEntryTimes() - this is a method that allows you to set times on the zip entries within the zip file.  I don't think you want to fiddle with the date and time on the entries within the zip file, if I understood your original request correctly.  What you want is the current date and time - and you want to use that to build the name of the zip file.  I think.  If you use the line I provided above, it should work.

I should say: yours is really not a question about DotNetZip; it's about the DateTime class, or more to the point, how to get the current time in a VB.NET application, and then use it to create a filename.

good luck.


Nov 7, 2010 at 8:59 PM

Works as recommeded! You are right. It is more like a VB.NET question. Sorry about that. I believe that I do have a DotNetZip question coming but I will open a new tread for that. Thanks!