|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Convetting string/text to datetimeI'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 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 DateTime.Parse(...) will do the trick! Youcan also use>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 > Convert.ToDateTime(...). 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 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, -- Show quoteHide quoteIgnacio 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 > 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 >> > >
Other interesting topics
Why exception when going through the DataSet?
How to show a datetime field in a TextBox Question about Sockets Problem with deriving System.EventArgs setting security from code Programmatically retrieving photos String vs string ComboBox find item based on value How to call ASP page from C# application? (string)dr["FieldName"] vs dr["FieldName"].ToString(); |
|||||||||||||||||||||||