Home All Groups Group Topic Archive Search About

Convetting string/text to datetime

Author
28 Mar 2005 2:24 PM
Randel Bjorkquist
I'm extremely new to C# and the Microsoft Visual Studio IDE.  I'm writing a
small web-application that executes a SQL Server stored procedure.  For the
most part, I have it working.  I am at the point where I now just need to
pass two more fields to the stored procedure, they are both to be date
values.

I have on my web form, two TextBoxes that I am pulling the value from.
However, I have not found a way to convert a string, or text value, to a
date value.  What I have found is a DateTime class, but all of its
constructors take numeric values to its parameters and not text.  I looked
under the "string" class but didn't see any methods that would help me.

Can someone point me into the right direction?  Any small, easy example
would be helpfull.

Thanks,

Randel Bjorkquist

Author
28 Mar 2005 2:28 PM
Ludwig Stuyck
On Mon, 28 Mar 2005 08:24:38 -0600, "Randel Bjorkquist"
<rbjorkqu***@coilcraft.com> wrote:

Show quoteHide quote
>I'm extremely new to C# and the Microsoft Visual Studio IDE.  I'm writing a
>small web-application that executes a SQL Server stored procedure.  For the
>most part, I have it working.  I am at the point where I now just need to
>pass two more fields to the stored procedure, they are both to be date
>values.
>
>I have on my web form, two TextBoxes that I am pulling the value from.
>However, I have not found a way to convert a string, or text value, to a
>date value.  What I have found is a DateTime class, but all of its
>constructors take numeric values to its parameters and not text.  I looked
>under the "string" class but didn't see any methods that would help me.
>
>Can someone point me into the right direction?  Any small, easy example
>would be helpfull.
>
>Thanks,
>
>Randel Bjorkquist
>

DateTime.Parse(...) will do the trick! Youcan also use
Convert.ToDateTime(...).

Are all your drivers up to date? click for free checkup

Author
28 Mar 2005 2:38 PM
Randel Bjorkquist
Hi Ludwig,

I keep forgetting about the "parse" method.

Thanks for your help,

Randel Bjorkquist


Show quoteHide quote
"Ludwig Stuyck" <ludwig.stuyck(remo***@coders-lab.be> wrote in message
news:325g419qcdljsi0j7oakstee14utsj09cp@4ax.com...
> On Mon, 28 Mar 2005 08:24:38 -0600, "Randel Bjorkquist"
> <rbjorkqu***@coilcraft.com> wrote:
>
>>I'm extremely new to C# and the Microsoft Visual Studio IDE.  I'm writing
>>a
>>small web-application that executes a SQL Server stored procedure.  For
>>the
>>most part, I have it working.  I am at the point where I now just need to
>>pass two more fields to the stored procedure, they are both to be date
>>values.
>>
>>I have on my web form, two TextBoxes that I am pulling the value from.
>>However, I have not found a way to convert a string, or text value, to a
>>date value.  What I have found is a DateTime class, but all of its
>>constructors take numeric values to its parameters and not text.  I looked
>>under the "string" class but didn't see any methods that would help me.
>>
>>Can someone point me into the right direction?  Any small, easy example
>>would be helpfull.
>>
>>Thanks,
>>
>>Randel Bjorkquist
>>
>
> DateTime.Parse(...) will do the trick! Youcan also use
> Convert.ToDateTime(...).
>
> --
> Ludwig Stuyck
> http://www.coders-lab.net
Author
28 Mar 2005 2:39 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,

You could use DateTime.Parse or DateTime.ParseExact , a couple of remarks
though.
1- They throw exceptions if the string is not in the correct format, so you
better use a try block
2- It's a good idea to use also a Calendar web control, this makes it easier
for the users to enter values
3- Use page validators in the textboxes, to make sure that the text is in
fact a correct date expression.


hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation




Show quoteHide quote
"Randel Bjorkquist" <rbjorkqu***@coilcraft.com> wrote in message
news:Oe2XgH6MFHA.2384@tk2msftngp13.phx.gbl...
> I'm extremely new to C# and the Microsoft Visual Studio IDE.  I'm writing
> a small web-application that executes a SQL Server stored procedure.  For
> the most part, I have it working.  I am at the point where I now just need
> to pass two more fields to the stored procedure, they are both to be date
> values.
>
> I have on my web form, two TextBoxes that I am pulling the value from.
> However, I have not found a way to convert a string, or text value, to a
> date value.  What I have found is a DateTime class, but all of its
> constructors take numeric values to its parameters and not text.  I looked
> under the "string" class but didn't see any methods that would help me.
>
> Can someone point me into the right direction?  Any small, easy example
> would be helpfull.
>
> Thanks,
>
> Randel Bjorkquist
>
Author
28 Mar 2005 7:56 PM
Randel Bjorkquist
Hey Ignacio,

Thanks for the help.  I had just started looking into managing the
exceptions these might throw, when I checked back and saw your message.

Again, thanks,

Randel Bjorkquist

Show quoteHide quote
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eBRB3P6MFHA.3336@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> You could use DateTime.Parse or DateTime.ParseExact , a couple of remarks
> though.
> 1- They throw exceptions if the string is not in the correct format, so
> you better use a try block
> 2- It's a good idea to use also a Calendar web control, this makes it
> easier for the users to enter values
> 3- Use page validators in the textboxes, to make sure that the text is in
> fact a correct date expression.
>
>
> hope this help,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
>
>
> "Randel Bjorkquist" <rbjorkqu***@coilcraft.com> wrote in message
> news:Oe2XgH6MFHA.2384@tk2msftngp13.phx.gbl...
>> I'm extremely new to C# and the Microsoft Visual Studio IDE.  I'm writing
>> a small web-application that executes a SQL Server stored procedure.  For
>> the most part, I have it working.  I am at the point where I now just
>> need to pass two more fields to the stored procedure, they are both to be
>> date values.
>>
>> I have on my web form, two TextBoxes that I am pulling the value from.
>> However, I have not found a way to convert a string, or text value, to a
>> date value.  What I have found is a DateTime class, but all of its
>> constructors take numeric values to its parameters and not text.  I
>> looked under the "string" class but didn't see any methods that would
>> help me.
>>
>> Can someone point me into the right direction?  Any small, easy example
>> would be helpfull.
>>
>> Thanks,
>>
>> Randel Bjorkquist
>>
>
>

Bookmark and Share