By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,256 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,256 IT Pros & Developers. It's quick & easy.

Need help getting two digit month and day values...

P: n/a
Hello All!

I have written a simple app that auto downloads a file from a secure
ftp, renames it, and moves it to a network location. Everything works
great except the renaming part. I parse out the last write date to get
the new filename, but the days and month are only single digits! This is
a problem when you reach something like 01/11/2004 and 11/1/2004, I get
dup filenames! ie.. 2004111.txt.
any idea on how I can rename these files with 2 digit values?

TIA

Luis
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Tue, 09 Nov 2004 10:05:48 -0500, Anon <an**@anon.com> wrote:
Hello All!

I have written a simple app that auto downloads a file from a secure
ftp, renames it, and moves it to a network location. Everything works
great except the renaming part. I parse out the last write date to get
the new filename, but the days and month are only single digits! This is
a problem when you reach something like 01/11/2004 and 11/1/2004, I get
dup filenames! ie.. 2004111.txt.
any idea on how I can rename these files with 2 digit values?

TIA

Luis


Build it with String.Format() like this:

Dim theTime As DateTime = Now 'Or whenever..

Dim szFilename As String = String.Format( _
"{0:D4}{1:D2}{2:D2}.TXT", _
theTime.Year(),
theTime.Month(),
theTime.Day())
// CHRIS

Nov 21 '05 #2

P: n/a
Anon,
I would use a format string such as:

Const format As String = "{0:yyyyMMdd}.txt"

Dim theDate As DateTime = DateTime.Now

Dim szFilename As String = String.Format( format, theDate)

Alternatively you could use:

Dim szFilename = theDate.ToString("yyyyMMdd") & ".txt"

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay

"Anon" <an**@anon.com> wrote in message
news:OC*************@TK2MSFTNGP11.phx.gbl...
Hello All!

I have written a simple app that auto downloads a file from a secure ftp,
renames it, and moves it to a network location. Everything works great
except the renaming part. I parse out the last write date to get the new
filename, but the days and month are only single digits! This is a problem
when you reach something like 01/11/2004 and 11/1/2004, I get dup
filenames! ie.. 2004111.txt.
any idea on how I can rename these files with 2 digit values?

TIA

Luis

Nov 21 '05 #3

P: n/a
Wow, i used the first response first and it worked great and my next
question was what it all meant. I understand, just not 100%, thanks for
the links and all of the help!!

Luis

Jay B. Harlow [MVP - Outlook] wrote:
Anon,
I would use a format string such as:

Const format As String = "{0:yyyyMMdd}.txt"

Dim theDate As DateTime = DateTime.Now

Dim szFilename As String = String.Format( format, theDate)

Alternatively you could use:

Dim szFilename = theDate.ToString("yyyyMMdd") & ".txt"

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay

"Anon" <an**@anon.com> wrote in message
news:OC*************@TK2MSFTNGP11.phx.gbl...
Hello All!

I have written a simple app that auto downloads a file from a secure ftp,
renames it, and moves it to a network location. Everything works great
except the renaming part. I parse out the last write date to get the new
filename, but the days and month are only single digits! This is a problem
when you reach something like 01/11/2004 and 11/1/2004, I get dup
filenames! ie.. 2004111.txt.
any idea on how I can rename these files with 2 digit values?

TIA

Luis


Nov 21 '05 #4

P: n/a
Anon,
String.Format expects a format specifier and zero or more arguments
(ParamArray).

The format specifier is a string that has zero or more placeholders (one for
each argument). The place holders are in curly braces {}. The number
indicates which argument to use. The info after the : in the curly braces is
used to format the argument. In this case argument zero is a date, so info
specifies a custom date format. The custom date format "yyyyMMdd" says we
want a 4 digit year, a 2 digit month, and a 2 digit day. Basically
String.Format takes the format from the placeholder & calls ToString with
the format, as my second example is doing directly.

The second link (along with its sub topics) should explain in detail how
both work.

Jay
"Anon" <an**@anon.com> wrote in message
news:eY**************@TK2MSFTNGP09.phx.gbl...
Wow, i used the first response first and it worked great and my next
question was what it all meant. I understand, just not 100%, thanks for
the links and all of the help!!

Luis

Jay B. Harlow [MVP - Outlook] wrote:
Anon,
I would use a format string such as:

Const format As String = "{0:yyyyMMdd}.txt"

Dim theDate As DateTime = DateTime.Now

Dim szFilename As String = String.Format( format, theDate)

Alternatively you could use:

Dim szFilename = theDate.ToString("yyyyMMdd") & ".txt"

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay

"Anon" <an**@anon.com> wrote in message
news:OC*************@TK2MSFTNGP11.phx.gbl...
Hello All!

I have written a simple app that auto downloads a file from a secure ftp,
renames it, and moves it to a network location. Everything works great
except the renaming part. I parse out the last write date to get the new
filename, but the days and month are only single digits! This is a
problem when you reach something like 01/11/2004 and 11/1/2004, I get dup
filenames! ie.. 2004111.txt.
any idea on how I can rename these files with 2 digit values?

TIA

Luis



Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.