473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
4 8859
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold...
1
by: Ian | last post by:
I have a report that shows a date along with many other fields, I am trying to keep this date field as small as possible to make room for other fields so I want it to be a 6 digit date. My...
7
by: jack | last post by:
Hello, I need to get the time down the the 0.1 second in a number string. Example 09-06-03 13:45 23.4 Seconds To "0906031345234"
5
by: Ray | last post by:
Dear all, Now, I can get the time using the code "DateTime.Now.ToString("hhmm")". If the time is 18:00, the result I get will be "0600". How can I get the result "1800"? Please help. Thanks, Ray
13
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Using VB2005, a datagridview is displaying the dates with 4 digit years on one workstation but displays the dates of the exact same records with only 2 digit years on a 2nd workstation. I will...
3
by: aashishn86 | last post by:
var weekend = ; var weekendColor = "#e0e0e0"; var fontface = "Verdana"; var fontsize = 1; var gNow = new Date(); var ggWinCal; isNav = (navigator.appName.indexOf("Netscape") != -1) ? true :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.