473,503 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convetting string/text to datetime

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
Nov 17 '05 #1
4 2095
On Mon, 28 Mar 2005 08:24:38 -0600, "Randel Bjorkquist"
<rb*********@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
Nov 17 '05 #2
Hi Ludwig,

I keep forgetting about the "parse" method.

Thanks for your help,

Randel Bjorkquist
"Ludwig Stuyck" <ludwig.stuyck(remove)@coders-lab.be> wrote in message
news:32********************************@4ax.com...
On Mon, 28 Mar 2005 08:24:38 -0600, "Randel Bjorkquist"
<rb*********@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

Nov 17 '05 #3
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" <rb*********@coilcraft.com> wrote in message
news:Oe**************@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

Nov 17 '05 #4
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

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eB**************@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" <rb*********@coilcraft.com> wrote in message
news:Oe**************@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


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1351
by: Tim::.. | last post by:
Hi I'm trying to create a pager that allows you to show records by year and month! I am getting close but would really appritiate some help! Can someone please tell me how I convert the value of...
0
4845
by: RSH | last post by:
I am having a bit of trouble filling a datatable with a query. I'm getting the error message: System.FormatException: String was not recognized as a valid DateTime. at...
11
7168
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
4899
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
6
4114
by: B.N.Prabhu | last post by:
Hi, I am having a DataTable which one column is in string format now i want to change that one to DataTime. I don't know whether its in datetime format or not i have to check if it is in...
5
5127
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
4
7210
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
9
451
by: Hrvoje Voda | last post by:
How to convert text from textbox "12.05.1977" into "12/05/1977"? and also check if the text is in right format before converting? Hrcko
3
212
by: DaveL | last post by:
I have Data Comming In in the format YYYYmmdd 01012008 does net have a conversion for this type of string to get it back to a DateTime or do i have to Regx or substring it out Thanks DaveL
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.