The first thing that you need to remember, Bruce, is that the DateString
function does not return a Date. Instaed it returns a string that represents
the current Date formatted as MM-dd-yyyy.
This is the same value that is returned by
DateTime.Today. ToString("MM-dd-yyyy") and also
DateTime.Now.To String("MM-dd-yyyy"). If your Regional Short Date setting is
set to MM-dd-yyyy then the same value is also returned by
DateTime.Today. ToString("d") and DateTime.Now.To String("d").
If all you will ever need is the date in MM-dd-yyyy fomat then fine, but the
multitude of date formatting options provides you with so many more options.
As to log files, the questions you need to ask yourself include:
1. Will the program write a new logfile each time it runs?
2. Will the program run multiple times in any one day?
3. Will the log files need to be accessed by anyone else apart from me?
If (1) is true and (2) is true then you're going to run into problems
because subsequent runs in the same day will overwrite the log files from
previous runs on that day.
If (3) is true then the naming convention for the log files must be such
that they know, unambiguously, what it is they are looking at, i.e. when the
file is named 01-02-2007.log, they must be absolutely aware that the file
relates to the 2nd of January and not the 1st of February.
I use log files extensively, not only to log critical activity, but also for
diagnostic information.
When I am using a new log file for each day, the naming convention I use is
yyyyMMdd.log and everybody who has to deal with such file knows that the
name is in that format.
When I am using a new log file for each month, the naming convention I use
is yyyyMM.log and, again, everybody who has to deal with such file knows
that the name is in that format.
The most important thing is to be absolutely consistent with what you do. If
you chop and change then you will end up confusing yourself.
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:ZI******** *************** *******@comcast .com...
I've almost completed my little application for work. This weekend I've
been working on Streams so I can write a logfile showing the work that was
accomplished. Wanting to make each logfile programmaticall y unique, I
decided to include the date that the log was written as a part of it's
filename. I was looking through all of the date stuff and all the posts
about formatting and was wondering how in the world I was going to get all
of that in a sub the way I wanted. I was searching for a way to format
JUST the date and ran into the 'DateString' method. It gave me exactly
what I was looking for without a lot of extra work, but I was wondering...
and here's the question... is there something substandard with this
method? In the newsgroup here I've seen folks wanting JUST a date and the
answers have really been strong on formatting, which the DateString
doesn't require.