473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

date Time variable in c#

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
Nov 19 '05 #1
5 11893
C# is case sensitive:

System.DateTime x;

or you there's a "using System;" at the top, you can just use

using System;

class Foo
{
void Bar()
{
DateTime x;
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #2
What doesn't work?

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

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"AirWalker" <Ai*******@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
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

Nov 19 '05 #3
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.
Nov 19 '05 #4
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.

"AirWalker" <Ai*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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.

Nov 19 '05 #5
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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Siva M" <sh******@online.excite.com> wrote in message
news:uP**************@TK2MSFTNGP10.phx.gbl...
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.

"AirWalker" <Ai*******@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
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.

Nov 19 '05 #6

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

Similar topics

13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
4
by: Gord | last post by:
Hello, VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into a database I'm creating by verifying that an appropriate Date or Time value has been entered. Using built-in...
3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
1
by: ESPNSTI | last post by:
Hi, I'd like to be able to distinguish between a DateTime variable that is allowed to hold both date and time and a DateTime variable that is allowed to only hold a Date. The reason's for this...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
2
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
4
by: Terry | last post by:
I have a TextBox with a date such as 15/01/2006 which I want to cast into a variable as a short date 15/01/06, also I need to cast a time such as 07:30 A.M. into a variable as a short time. What...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.