473,387 Members | 1,891 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,387 software developers and data experts.

Data Types of datetime and bit

Tom
Hi,

I have a DB table in which has 2 attributes:
1. RegistrationDate datetime
2. IsApproved bit //Approved = 0; Not approve = 1

Now, I need to get and set their values in cs files.

public XXX RegistrationDate / IsApproved
{
get
{
return this.Date; / this.IsApproved;
}
set
{
this.Date = value; / this.IsApproved;
}
}

I want to know what are the data types of datetime and bit in C#?

Do I use string and int for them?

Also, for the datetime, how can I get the system date and time? and what are their formats? DD/MM/YY SS/MM/HH ?

Thanks for help

Tom
Nov 15 '05 #1
5 7852
C# has a DateTime class that hold a bunch of different or user define
datetime formats.
As for bit ... well, there is Boolean (bool) but it's not really 1 or 0.
Someone else might know more about it.

As for system date and time, use DateTime.Now. It can output date and
time in whatever format you want.

--
The hotmail account will most likely not be read, so please respond only
to the news group.
Nov 15 '05 #2
you can use short or int for the bit type. In DB any non-zero number will be
converted to 1 and if 0 to 0 appropriately

datetime type you can represent as string "YYYY-MM-DD HH:MM:SS" if you are
executing queries as simple string.

for example
create table test1 (id bigint, value bit, time datetime)

insert into test1 values (1, 0, '2005-01-01 8:35:00')
insert into test1 values (1, -2, '2000-01-01 8:35:00')
insert into test1 values (1, 122, '2000-01-01 8:35:00')

will produce
id value time
1 0 2005-01-01 8:35:00.000
1 1 2000-01-01 8:35:00.000
1 1 2000-01-01 8:35:00.000
"Tom" <ke*****@yahoo.com> wrote in message
news:6F**********************************@microsof t.com...
Hi,

I have a DB table in which has 2 attributes:
1. RegistrationDate datetime
2. IsApproved bit //Approved = 0; Not approve = 1

Now, I need to get and set their values in cs files.

public XXX RegistrationDate / IsApproved
{
get
{
return this.Date; / this.IsApproved;
}
set
{
this.Date = value; / this.IsApproved;
}
}

I want to know what are the data types of datetime and bit in C#?

Do I use string and int for them?

Also, for the datetime, how can I get the system date and time? and what are their formats? DD/MM/YY SS/MM/HH ?
Thanks for help

Tom

Nov 15 '05 #3
Tom
Hi

I read http://msdn.microsoft.com/library/de...classtopic.asp and saw DateTime is a data type.

When I add using System.DateTime, the VS.net does not have that library. I cannot add it as new reference

So, which library should I add to reference

Thanks
Nov 15 '05 #4
Tom <ke*****@yahoo.com> wrote:
I read
http://msdn.microsoft.com/library/de...ary/en-us/cpre
f/html/frlrfsystemdatetimeclasstopic.asp and saw DateTime is a data
type.

When I add using System.DateTime, the VS.net does not have that
library. I cannot add it as new reference.

So, which library should I add to reference?


You shouldn't need to - what exact error message are you getting? Could
you post some code which shows the problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Tom
Hi

There is a datetime type with length 8 in a table

I tried to insert the Local System datetime to it from aspx.cs file. But, the outcome are

string sysdatetime = System.DateTime.Now.ToShortDateString(); //output 1900-01-01 00:00:00.000
string sysdatetime = System.DateTime.Now.ToLongDateString(); //output 1900-01-01 00:00:00.000
string sysdatetime = System.DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss"); //output 1/1/1900
DateTime sysdatetime = System.DateTime.Now; //Compile error. Cannot convert char to datetim

They cannot output current datetime. How should I fix it

And, how can I get only Date 1900-01-01, only Time 00:00:00 or both DateTime 1900-01-01 00:00:00

Thanks
Nov 15 '05 #6

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

Similar topics

4
by: Nathon Dalton | last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples For string I use this If Not abc.text Is Nothing AndAlso Not...
1
by: E. R. Retzloff | last post by:
Any suggestions on how to track a NULL value received from SQL Server in a DateTime field? I have come up with two and I'm not convinced either of them are good solutions. 1. Assign a...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
9
by: John | last post by:
If a value type is immutable, I guess it's threadsafe to read it? But not threadsafe to assign a new value to it (can any value type be truely immutable? Isn't assigning a totally new value to it,...
3
by: aaa | last post by:
I am having trouble getting a complex data type to get passed to a non-COM dll's function by ref and return back data from that object. Simple data types work fine but when I try the complex data...
9
by: Bob | last post by:
I have a sql command with a SearchDate parameter of type date. When I execute its stored procedure from Query Analyzer (to SS2K) with a date out of the valid datetime range, EXEC @SearchDate =...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
5
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
7
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.