date Time variable in c#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how do I decalre a variable as a datetime datatype in c#

for example a variable called 'x'

i've tried private DateTime x,
and i've tried system.datetime x

but none seem to work

does anyone have the solution

much appreciated
 
What doesn't work?

both should work....do you want to intialize it to a particular date as
well?

Karl
 
What im trying to do is declare a variable(startDate) as a datetime, this
variable will be the inputted by a user at runtime into a textbox as a date.
Then that value of textbox will be inserted to a column in a sql database
which has a datetime column.
 
Not sure if this is what you are looking for:

DateTime x;
x = DateTime.Parse(TextBox.Text); // or use DateTime.ParseExact() if you
have fixed format
// Use x now to insert into the database table.

What im trying to do is declare a variable(startDate) as a datetime, this
variable will be the inputted by a user at runtime into a textbox as a date.
Then that value of textbox will be inserted to a column in a sql database
which has a datetime column.
 
Just note that DateTime.Parse() might throw an exception if it can't
parse...ie if the user entered "aaa" so either validate or use a try catch
and catch for the specific exceptions..

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top