Re: dateTime Manupulations

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 10/20/04


Date: Wed, 20 Oct 2004 13:30:28 -0500

Cor,
(shakes head)

Oh! really, then we must be reading different messages!

Reny stated:
<quote>
Hi,
I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
miniute to it.How can i do that?
by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
12:00 AM'
How do i do that?
Reny
</quote>

Notice the quoted string, a specific format for a date & time. Also notice
he says he wants to take a variable (which may be a string that happens to
have a date in it), and do something with it. If he does have a string, he
will need to convert that string into a DateTime.

Z. f. stated:
<quote>
HI,
i have string in format
dd/mm/yyyyy hh:mm:ss
and giving this as an input to DateTime.Parse gives a string was not
recognized as a valid date time format string error.
how do i make the parse method to accept formatting that i need.
if i do console.writeLine DateTime.Now.ToString it gives the format:
YYYY-MM-DD HH:MM:SS

TIA, Z.
</quote>

Notice the second line, a specific format for a date & time, also notice he
states "how do i make the parse method".

> In none of the threads I have read explicitly that there was needed a
> datetime conversion between strings, however it was a datetime conversion
> between a datetime value and a string value.

In zf's case he stated explicitly "I have a string".

In Reny's case you are correct he simply states "I have a variable", I
noticed that both your & my example assume a string variable as input, it
could very well be that his variable is a datetime variable and in both
cases conversion is not necessary (which is why I asked in my original
response to him).

I noticed your posts don't discuss formatting the output per se either,
instead you rely on changing the currentculture...

> So show me first where that culture conversion is needed before you start
> to tell that for conversion between a string and a date a CDate is not the
> best choise.
That's the point, there is no culture conversion, as a specific date time
format is given, a string is give, and the OP wants a DateTime value
returned. CDate using the current culture, hence there is a culture
conversion. As Jon & I discussed yesterday DateTime.ParseExact does not
involve any culture when you give it a specific format!

As I stated:
>> In closing, I sincerely hope you will take the time & reread both of
>> these threads and make a concerted effort to understand why a number of
>> us may be saying that in these two specific cases using
>> DateTime.ParseExact might be better then relying solely on CDate.
>> Hopefully you will realize that the blinders are just a little too tight.

Hope this helps
Jay

"Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
news:ej4xHastEHA.2808@TK2MSFTNGP14.phx.gbl...
> Jay,
>
> Your message shows only that you completly did not read my message or
> completly do not understand what is the situation where it is in real
> business needed to convert a datetimestring to another culture.
>
> In none of the threads I have read explicitly that there was needed a
> datetime conversion between strings, however it was a datetime conversion
> between a datetime value and a string value.
>
> So show me first where that culture conversion is needed before you start
> to tell that for conversion between a string and a date a CDate is not the
> best choise.
>
> Cor
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com>
>> Cor,
>> It seems to me you have the blinders on a just a little too tight. :-|
>>
>> In other words you are only seeing CDate, where as you might want to look
>> to the side & see DateTime.ParseExact also!
>>
>> I agree using the VB Convert Functions in most cases is the way to go.
>> However like any rule there are exceptions. As has been demonstrated,
>> converting a DateTime with a specific format is one of those exceptions.
>>
>> An analogy might be a Carpenter. Does a (good) carpenter have a single
>> hammer? No, they have 2 or 3 kinds of hammers, as each is needed
>> depending on what he is doing. Does he have a single screwdriver? No, he
>> has standard (or slotted) and Phillips, plus possible a whole slew of
>> others. Does he have a single size of screwdriver? No he has #0 thru #4
>> sizes based on the requirements of the specific job.
>>
>> The Carpenter has different tools & sizes & shapes of the "same" tool, as
>> each is required for a specific job. Same with CDate &
>> DateTime.ParseExact. Most of the time CDate (a #2 slotted screwdriver) is
>> fine, however sometimes you need a specialized tool, such as
>> DateTime.ParseExact (a #0 slotted screwdriver).
>>
>> For the life of me, I really don't understand why you don't see this.
>> Reading Reny & z.'s earlier question both stated, in a specific format,
>> which to a number of developers myself included, suggests that
>> DateTime.ParseExact with a specific format string is the correct method
>> in this instance.
>>
>> I hope you realize I am not saying don't use CDate, as I use it where
>> CDate makes sense.
>>
>> What I am saying is that CDate does not make sense in this case. For some
>> reason you are not accepting this, from Herfried, Jon, myself or others.
>> I really don't know why, or how we can better explain it.
>>
>> In closing, I sincerely hope you will take the time & reread both of
>> these threads and make a concerted effort to understand why a number of
>> us may be saying that in these two specific cases using
>> DateTime.ParseExact might be better then relying solely on CDate.
>> Hopefully you will realize that the blinders are just a little too tight.
>>
>> Hope this helps
>> Jay
>>
>>
>> "Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
>> news:%23iM$thrtEHA.3564@tk2msftngp13.phx.gbl...
>>> Jay,
>>>
>>> I just following the advice from the VBNet pages to use the Convert
>>> Functions from which I understand it is advices to use them because they
>>> give the best overall performance.
>>>
>>> Although when those advices were not given do I find them very clear to
>>> use and easy. I find them one of the best extra parts of VBNet.
>>>
>>> Because of all that doing, from Herfried and others who say that when
>>> someone who asks how to set a date and time, and than gives with that a
>>> format string, particulary wants to use change a format not in his own
>>> local format I give now that other situation.
>>>
>>> In my opinion are those datestring information more given as extra
>>> information for us (what format the OP is using) than that he directly
>>> wants to convert the format. I did not by accident give the Australian
>>> format when I saw the time of the message. However that was a gues.
>>>
>>> Beside that can I only think of one situation where it is needed to
>>> change the dateandtime given in a culture and that is with a webformpage
>>> or with any other document where that is in.
>>>
>>> Than it is better in my opinion to set in the class that processes that
>>> first the right language/culture and set that back at the end of the
>>> class. Doing that for every instruction inside will give in my idea more
>>> dangerous code when there is maintanance.
>>>
>>> That has nothing to do with understanding. Sometimes I get the idea that
>>> you think that I write things because of lack of knowledge.
>>>
>>> For me are rules as 80/20 and "keep it simple" very important. A program
>>> have to be made however mostly as well will there be maintenance on it.
>>>
>>> I hope that you can share my opinion above and understand why I am
>>> telling this about globalization.
>>>
>>> Cor
>>>
>>>
>> <<snip>>
>>
>
>



Relevant Pages

  • Proposal: String::Format::General
    ... It provides format string parsing and output assembly, you provide the code that implements the individual conversion characters. ... Format syntax is kind of a cross between sprintf and strftime, but how close it is to each of these depends on the semantics implemented by the user. ... Note that the following is pre-alpha documentation; the interface to the output conversion code has changed since yesterday, ... conversion character, and contain a number of optional fields which may ...
    (comp.lang.perl.modules)
  • Proposal: String::Format::General
    ... It's almost a meta-formatter with the user providing individual conversion code behind a sprintf/strftime-like interface. ... A format is basically a string into which data are to be inserted. ... conversion character, and contain a number of optional fields which may ...
    (comp.lang.perl.modules)
  • Re: Proposal: String::Format::General
    ... It's almost a meta-formatter with the user providing individual conversion code behind a sprintf/strftime-like interface. ... A format is basically a string into which data are to be inserted. ... conversion character, and contain a number of optional fields which may ...
    (comp.lang.perl.modules)
  • Re: Axis <-> .Net xsd:date interoperability problem
    ... .NET can de-serialize from alternative string representations of the date, ... but you need to tell it the format to expect. ... DateTime to be set. ... serialization of all DateTime's. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: convert a date to a string?
    ... converting it to a CHARACTER string. ... Also, don't convert it back to a datetime, or put it in a datetime variable, ... or you'll lose the format. ... >>> Declare @m int ...
    (microsoft.public.sqlserver.programming)