Small question?

  • Thread starter Thread starter Bruce W. Darby
  • Start date Start date
B

Bruce W. Darby

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 programmatically 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.
 
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.

Have you taken a look at Log4Net or Microsoft's Enterprise logging blocks?
strong on formatting, which the DateString doesn't require.

What a rambling post - have you taken a look at now().ShortDate? That
formats the date to the local regional settings.

Otherwise you can use the FormatDateTime command specify your own format.
 
Bruce,

I did not knew this function. Not so strange:. if I understand it well, than
it is outside the USA completely useless.

In my idea is this construction beneath the nicest for your purpose

Dim mylogfiledate As String = Now.ToString("yyyyMMddhhmmss")
I hope this helps,

Cor
 
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.ToString("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.ToString("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.
 
Spam Catcher said:
Have you taken a look at Log4Net or Microsoft's Enterprise logging blocks?

Actually, no, I haven't. :) I'm working this little tool up myself on my own
time for work so I can extend my understanding of programming and the .Net
environment. As such, I look at what is avail 'at the time'. Would I require
the Enterprise version of VS2995 to use the logging blocks? As it is, I only
have the Standard Edition.
What a rambling post - have you taken a look at now().ShortDate? That
formats the date to the local regional settings.

Otherwise you can use the FormatDateTime command specify your own format.

Sorry for rambling, but I just wanted to provide some data that I wasn't
sure was widely known.
 
I did not knew this function. Not so strange:. if I understand it well,
than it is outside the USA completely useless.

I didn't see any warnings that it would not be useful outside the United
States. Perhaps it's a method that is much the same as the 'Shortdate'
method SpamCatcher mentioned.
In my idea is this construction beneath the nicest for your purpose

Dim mylogfiledate As String = Now.ToString("yyyyMMddhhmmss")
I hope this helps,

Thanks for the formatting string above, Cor. If you didn't want the hours,
minutes, seconds, I take it that you just don't include them in the
formatting string? I'll keep it in mind, but what I was actually doing is
concatenating the date into the file path, as in...

Dim strFullFilename As String = strPathName & "\" & DateString &
[filename.ext]

DateString returns a string formatted as 12-25-2006, which worked perfectly
for what I needed.

When I attempted to use another Date format, the slashes in the date were
interpreted as directory seperators and it created a directory structure
where12 was its own directory with a subdirectory of 25, etc.

I'm learning... thanks for your input!
 
As to log files, the questions you need to ask yourself include:
1. Will the program write a new logfile each time it runs?

Yes. :)
2. Will the program run multiple times in any one day?

EXTREMELY doubtful
3. Will the log files need to be accessed by anyone else apart from me?

The VP probably. We're a small company with 5 employees, so it's me or him.
LOL I've included a sample of the actual filename syntax in my response to
Cor. I wanted to make absolutely certain that my logfiles were descriptive
AND unique. I anticipate having to run the utility about once a week at the
most, so this naming system should suffice quite nicely. If it needs to be
changed at a later date, I can do a revision quickly. And I can totally
understand the communication issues and the need to be consistent. Thanks
again.
 
Bruce,

If I have read it well, than DateString returns forever a MM dd yy format.
That format is only used in the USA and some Coca Cola cultures, (Think
about Japan when they are not using their own figurs but not on China). You
would believe that Canada had the same as the USA, but they have it like
England and I thought a more sophisticated way (not like France)..

You can see that it is confusing as Stephany shows. See always thinks that
more people know about those very different culture differences when writing
date and time. (it is not only the date it is as well with times), in my
idea are it only a few.

Somebody wrote ones in this newsgroup. I live in Australia, we will never
use American software because it gives always troubles with dates (Australia
has the same time standards as the USA). I assume that he meant with we his
company, before I get some responses from Stephany.

(I gave the full string, like Stephany I did not know how many times a day
you would write a log file, beside that is the ISO way better when you do a
Dir in your log directory).

Cor


Bruce W. Darby said:
I did not knew this function. Not so strange:. if I understand it well,
than it is outside the USA completely useless.

I didn't see any warnings that it would not be useful outside the United
States. Perhaps it's a method that is much the same as the 'Shortdate'
method SpamCatcher mentioned.
In my idea is this construction beneath the nicest for your purpose

Dim mylogfiledate As String = Now.ToString("yyyyMMddhhmmss")
I hope this helps,

Thanks for the formatting string above, Cor. If you didn't want the hours,
minutes, seconds, I take it that you just don't include them in the
formatting string? I'll keep it in mind, but what I was actually doing is
concatenating the date into the file path, as in...

Dim strFullFilename As String = strPathName & "\" & DateString &
[filename.ext]

DateString returns a string formatted as 12-25-2006, which worked
perfectly for what I needed.

When I attempted to use another Date format, the slashes in the date were
interpreted as directory seperators and it created a directory structure
where12 was its own directory with a subdirectory of 25, etc.

I'm learning... thanks for your input!
 
Cor,

Thanks for the information. I shall keep it uppermost in my mind about dates
and times.
Cor Ligthert said:
Bruce,

If I have read it well, than DateString returns forever a MM dd yy format.
That format is only used in the USA and some Coca Cola cultures, (Think
about Japan when they are not using their own figurs but not on China).
You would believe that Canada had the same as the USA, but they have it
like England and I thought a more sophisticated way (not like France)..

You can see that it is confusing as Stephany shows. See always thinks that
more people know about those very different culture differences when
writing date and time. (it is not only the date it is as well with times),
in my idea are it only a few.

Somebody wrote ones in this newsgroup. I live in Australia, we will never
use American software because it gives always troubles with dates
(Australia has the same time standards as the USA). I assume that he
meant with we his company, before I get some responses from Stephany.

(I gave the full string, like Stephany I did not know how many times a day
you would write a log file, beside that is the ISO way better when you do
a Dir in your log directory).

Cor


Bruce W. Darby said:
I did not knew this function. Not so strange:. if I understand it well,
than it is outside the USA completely useless.

I didn't see any warnings that it would not be useful outside the United
States. Perhaps it's a method that is much the same as the 'Shortdate'
method SpamCatcher mentioned.
In my idea is this construction beneath the nicest for your purpose

Dim mylogfiledate As String = Now.ToString("yyyyMMddhhmmss")
I hope this helps,

Thanks for the formatting string above, Cor. If you didn't want the
hours, minutes, seconds, I take it that you just don't include them in
the formatting string? I'll keep it in mind, but what I was actually
doing is concatenating the date into the file path, as in...

Dim strFullFilename As String = strPathName & "\" & DateString &
[filename.ext]

DateString returns a string formatted as 12-25-2006, which worked
perfectly for what I needed.

When I attempted to use another Date format, the slashes in the date were
interpreted as directory seperators and it created a directory structure
where12 was its own directory with a subdirectory of 25, etc.

I'm learning... thanks for your input!
 
How would you know what I always think or don't think, Cor!

And for your information I don't live in Australia!

If you had 'read it well' you will have noticed that DateString returns
'forever' a string in the MM-dd-yyyy format and not the MM dd yyyy format.

We programmers ALL know that differences in date formats are capable of
causing havoc within software. Thos who don't need to consider another
career. It is not rocket science to use the multitude of date formatting
techniques that will always deal with a date in the 'culture' of the user,
however, time and time again we see software that has 'hard-coded' date
formatting and I consider that to be nothing more than incompentence.

However, for software that will never be used outside a single 'shop' (as in
the application that Bruce has written) it is not unreasonable to settle
upon a single format. The same applies to software that will never be used
outside a single country where everyone uses the same format. Sometimes
people get to carried away in making an application usable by everyone in
the world when the only people who will ever use it are the ones who work 3
offices down the corridor.

I don't know about the Netherlands, but here in New Zealand we are taught in
primary school about the date format that we use in this country and about
the different date formats that are used in various other countries. We also
don't make judgements about whether a country is right or wrong to use the
format that they do and we don't go about telling them that they should use
the ISO format. To do so would be pure arrogance.

For your information, and if you bothered to do some basic research, you
would find that those countries of the world that come under the influence
of the USA, tend to use the the same date format that the USA does, e.g.,
USA, Puerto Rico, The Marianas, American Samoa, various parts of Micronesia
and various parts of the Carribean. Those countries of the world that come
under the influence of the UK or were part of what was called the British
Empire, thend to use the same date format as the UK does, e.g., New Zealand,
Australia, Canada, South Africa, most Pacific Island Nations and a number of
Carribean Island nations. It is really nothing more than accidents of
history.

Here in New Zealand, when speaking, we say 'the 1st of January', 'the 6th of
February', 'the 5th of November', 'the 11th of September', etc, which
correlates to our date format of dd/MM/yyyy. Also, on formal legal documents
you would see the date written as the phrase 'Dated this twenty-ninth day of
February'.

In the USA, when speaking, they say 'January the 1st 2005', 'May the 25th
2006', 'November the 10th 2007', 'September the 11th', etc, which correlates
to their date format of MM/dd/yyyy.

If a certain event had occurred in New Zealand instead of the USA, it would
be known as '11/9' rather than '9/11'.

I have often wondered why the USA uses the format they do (not that I loose
any sleep over it). I conjecture that it was probabaly to do with the
throwing away of various thing British as a result of 1776 and all that.


Cor Ligthert said:
Bruce,

If I have read it well, than DateString returns forever a MM dd yy format.
That format is only used in the USA and some Coca Cola cultures, (Think
about Japan when they are not using their own figurs but not on China).
You would believe that Canada had the same as the USA, but they have it
like England and I thought a more sophisticated way (not like France)..

You can see that it is confusing as Stephany shows. See always thinks that
more people know about those very different culture differences when
writing date and time. (it is not only the date it is as well with times),
in my idea are it only a few.

Somebody wrote ones in this newsgroup. I live in Australia, we will never
use American software because it gives always troubles with dates
(Australia has the same time standards as the USA). I assume that he
meant with we his company, before I get some responses from Stephany.

(I gave the full string, like Stephany I did not know how many times a day
you would write a log file, beside that is the ISO way better when you do
a Dir in your log directory).

Cor


Bruce W. Darby said:
I did not knew this function. Not so strange:. if I understand it well,
than it is outside the USA completely useless.

I didn't see any warnings that it would not be useful outside the United
States. Perhaps it's a method that is much the same as the 'Shortdate'
method SpamCatcher mentioned.
In my idea is this construction beneath the nicest for your purpose

Dim mylogfiledate As String = Now.ToString("yyyyMMddhhmmss")
I hope this helps,

Thanks for the formatting string above, Cor. If you didn't want the
hours, minutes, seconds, I take it that you just don't include them in
the formatting string? I'll keep it in mind, but what I was actually
doing is concatenating the date into the file path, as in...

Dim strFullFilename As String = strPathName & "\" & DateString &
[filename.ext]

DateString returns a string formatted as 12-25-2006, which worked
perfectly for what I needed.

When I attempted to use another Date format, the slashes in the date were
interpreted as directory seperators and it created a directory structure
where12 was its own directory with a subdirectory of 25, etc.

I'm learning... thanks for your input!
 
Here in New Zealand, when speaking, we say 'the 1st of January', 'the 6th
of February', 'the 5th of November', 'the 11th of September', etc, which
correlates to our date format of dd/MM/yyyy. Also, on formal legal
documents you would see the date written as the phrase 'Dated this
twenty-ninth day of February'.

In the USA, when speaking, they say 'January the 1st 2005', 'May the 25th
2006', 'November the 10th 2007', 'September the 11th', etc, which
correlates to their date format of MM/dd/yyyy.


You are close, Steph, but not completely right...

In the USA (which I was born and raised and still live), Jan. 1st, 2005 is
states 'January 1st, 2005'...no 'the' in between January and 1st. I'm not
sure where we came up or got our date format/layout/grammer, but I do know
how we speak it non-formally.

On legal documentation, we do it the same as you. 'Dated this twenty-ninth
day of February'...


:)

Mythran
 
Stephany,
How would you know what I always think or don't think, Cor!

I am glad that you were able to understand a part of my message, however
this part of my message can be not only confusing for you but for all not
regulars in this newsgroup. I have often seen you messages like this in
these newsgroup.

As I already wrote is this only confusing for people who use programs which
should work outside their culture and most others don't even know about the
differences.
And for your information I don't live in Australia!
Glad to know, I did not write that, however you have often showed that you
intend to know more from Australia than the average visitor of this
newsgroup. I thought the last time yesterday in about 10 messages.

What is the importance from this message; are you in love with your
keyboard?
I don't know about the Netherlands, but here in New Zealand we are taught
in primary school about the date format that we use in this country and
about the different date formats that are used in various other countries.
We also don't make judgements about whether a country is right or wrong to
use the format that they do and we don't go about telling them that they
should use the ISO format. To do so would be pure arrogance.
Again I cannot see this in any relation to the question or that what I
wrote.
For your information, and if you bothered to do some basic research, you
would find that those countries of the world that come under the influence
of the USA, tend to use the the same date format that the USA does, e.g.,
USA, Puerto Rico, The Marianas, American Samoa, various parts of
Micronesia and various parts of the Carribean. Those countries of the
world that come under the influence of the UK or were part of what was
called the British Empire, thend to use the same date format as the UK
does, e.g., New Zealand, Australia, Canada, South Africa, most Pacific
Island Nations and a number of Carribean Island nations. It is really
nothing more than accidents of history

For your information, there are more cultures in the world than those who
speak English.

Beside that is in South Africa used the same as in the Dutch spoken way
which splits the day at noon. The written way in the Netherlands is the same
as almost complete Europe containing the Spanish, the Portuguese, the German
(now official ISO), The French, The Italian and the Dutch cultures. The
former colonies from those countries which outnumber the given by you are
mostly using the same. However as you show often are that for you no
cultures. In Europe have some countries choosen the in fact for calculating
better ISO system, however that add nothing to the spoken way and is not
everywhere accepted. The most important real user of ISO is China.
I don't know about the Netherlands, but here in New Zealand we are taught
in primary school about the date format that we use in this country and
about the different date formats that are used in various other countries.
We also don't make judgements about whether a country is right or wrong to
use the format that they do and we don't go about telling them that they
should use the ISO format. To do so would be pure arrogance.

Only the English speaking or cultural related countries I assume as
conclusion from what you have written before. However writing in this way is
very arrogant. My sample for ISO dates was to use it in FileNames nowhere
more.

For your information, we don't learn that, however because most children
from the Benelux and Scandinavian countries speak very quick more than one
languages. Especially English because they are confronted with that when
they are on Internet, however in my idea not only the children from those
countries.
In the USA, when speaking, they say 'January the 1st 2005', 'May the 25th
2006', 'November the 10th 2007', 'September the 11th', etc, which
correlates to their date format of MM/dd/yyyy.

If a certain event had occurred in New Zealand instead of the USA, it
would be known as '11/9' rather than '9/11'

For whom are you telling this above, or are you really thinking that we are
all complete idiots?
I have often wondered why the USA uses the format they do (not that I
loose any sleep over it). I conjecture that it was probabaly to do with
the throwing away of various thing British as a result of 1776 and all
that.
In my idea because as far as I know September 11 at least originally in good
English spoken is as September Eleven and not in the way as you wrote. What
shows why the Americans are in fact using it correct. In the English
language it is a little bit more confusing than in other languages to choose
but the American way is 100% correct, they freed themselves only a little
bit earlier than the other British colonies and made their own decision.

Just some thoughts with more words than I normally use.

Cor
 
Actually, no, I haven't. :) I'm working this little tool up myself on
my own time for work so I can extend my understanding of programming
and the .Net environment. As such, I look at what is avail 'at the
time'. Would I require the Enterprise version of VS2995 to use the
logging blocks? As it is, I only have the Standard Edition.

I think any version of VS.NET should suffice for the Enterprise blocks.
MS has 2 editions of the blocks, one for .NET 1.1 and one for .NET 2.0.
These blocks handle everything from priority to filtering to multiple
output sources. It sort of defeats the purpose to write your own logging
block if you're going to be doing the same : )

Otherwise you're on the right track...

Sorry for rambling, but I just wanted to provide some data that I
wasn't sure was widely known.

It was a bit hard to read... that's all ;-)
 
Dennis is right, format it with the month spelt out as a word so there
won't be any confusion with the stupid american date format.

George
 
Back
Top