Data Types of datetime and bit

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

Guest

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
 
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.
 
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 said:
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 ?
 
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
 
Back
Top