date problem

Y

yoshitha

hi

db : sql server 2000
lan : C#.net(ASp.Net)

in my database table there are 2 fileds of data type datatime.

in field 1 i'm storing date

in field 2 i'm storing time.

in my textbox date is in the format of 2/12/2006 and i'm inserting as it

is.

and time is in teh fromat of 10:30 and i'm inserting as it is.

but after retrieving and displaying in data grid it is diplsying the

filed 1 like this.

2/12/2006 12:00:00 AM

and field is displaying like this.

1/1/1900 12:00:00 PM


but i need data to be displayed in field 1 as 2/12/2006
and in field 2 as 10:30.


can anybody tell me how to do this. its very urgent for me.


thanx in advacne

yoshitha
 
P

Patrice

I would do a trace to see which statement is sent. It lloks like updating
the time file dis missing from the statement.

As a side note you could perhaps store both the date and time into the same
filed even if the UI doesn't do this. It lloks like to me this is a single
information (and it could be easier when handling this in the db rather than
always adding those two files to do datetime comparisons).
 
S

S. Justin Gengo [MCP]

Yoshitha,

You'll only need one field in the database. The database's DateTime field is
always a combination of date and time. You should store your values as a
single datetime (SQL Server 2005 was supposed to include separate date and
time fields but they were removed from the final release....).

When you store your date and time in the server just combine them:

Dim MyDate As New DateTime([Year], [Month], [Day], [Hour], [Minute],
[Seconds])

SqlCommand1.Parameters.Add("@Date", Data.SqlDbType.DateTime).Value = MyDate

Then in your datagrid use string formatting to display just the portion you
want:

(You say your using a datagrid so I assume you're using .NET 1.1?)

<asp:BoundColumn DataField="CreateDate" HeaderText="Date"
DataFormatString="{0:d}">
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

Using the dataformat string you may display just the short date (lowercase
"d") and just the short time (lowercase "t") of the datetime column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Y

yoshitha

i used the follwoing statement in data grid
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

then it is showing time in 12 hours format but i want to display it as 24
hours format.
for eg in data base the data is stored as 18:30

and after using the above statement in the grid it is displaying 6:30
can you tell me how to display in 24 hours format?



S. Justin Gengo said:
Yoshitha,

You'll only need one field in the database. The database's DateTime field
is always a combination of date and time. You should store your values as
a single datetime (SQL Server 2005 was supposed to include separate date
and time fields but they were removed from the final release....).

When you store your date and time in the server just combine them:

Dim MyDate As New DateTime([Year], [Month], [Day], [Hour], [Minute],
[Seconds])

SqlCommand1.Parameters.Add("@Date", Data.SqlDbType.DateTime).Value =
MyDate

Then in your datagrid use string formatting to display just the portion
you want:

(You say your using a datagrid so I assume you're using .NET 1.1?)

<asp:BoundColumn DataField="CreateDate" HeaderText="Date"
DataFormatString="{0:d}">
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

Using the dataformat string you may display just the short date (lowercase
"d") and just the short time (lowercase "t") of the datetime column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
hi

db : sql server 2000
lan : C#.net(ASp.Net)

in my database table there are 2 fileds of data type datatime.

in field 1 i'm storing date

in field 2 i'm storing time.

in my textbox date is in the format of 2/12/2006 and i'm inserting as it

is.

and time is in teh fromat of 10:30 and i'm inserting as it is.

but after retrieving and displaying in data grid it is diplsying the

filed 1 like this.

2/12/2006 12:00:00 AM

and field is displaying like this.

1/1/1900 12:00:00 PM


but i need data to be displayed in field 1 as 2/12/2006
and in field 2 as 10:30.


can anybody tell me how to do this. its very urgent for me.


thanx in advacne

yoshitha
 
S

S. Justin Gengo [MCP]

Yoshitha,

Sure can!

Use uppercase "H" only for a 24-hour clock, and lowercase "h" only for a
12-hour clock. The AM/PM formats are replaced with "t" and "tt."

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
i used the follwoing statement in data grid
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

then it is showing time in 12 hours format but i want to display it as 24
hours format.
for eg in data base the data is stored as 18:30

and after using the above statement in the grid it is displaying 6:30
can you tell me how to display in 24 hours format?



S. Justin Gengo said:
Yoshitha,

You'll only need one field in the database. The database's DateTime field
is always a combination of date and time. You should store your values as
a single datetime (SQL Server 2005 was supposed to include separate date
and time fields but they were removed from the final release....).

When you store your date and time in the server just combine them:

Dim MyDate As New DateTime([Year], [Month], [Day], [Hour], [Minute],
[Seconds])

SqlCommand1.Parameters.Add("@Date", Data.SqlDbType.DateTime).Value =
MyDate

Then in your datagrid use string formatting to display just the portion
you want:

(You say your using a datagrid so I assume you're using .NET 1.1?)

<asp:BoundColumn DataField="CreateDate" HeaderText="Date"
DataFormatString="{0:d}">
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

Using the dataformat string you may display just the short date
(lowercase "d") and just the short time (lowercase "t") of the datetime
column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
hi

db : sql server 2000
lan : C#.net(ASp.Net)

in my database table there are 2 fileds of data type datatime.

in field 1 i'm storing date

in field 2 i'm storing time.

in my textbox date is in the format of 2/12/2006 and i'm inserting as it

is.

and time is in teh fromat of 10:30 and i'm inserting as it is.

but after retrieving and displaying in data grid it is diplsying the

filed 1 like this.

2/12/2006 12:00:00 AM

and field is displaying like this.

1/1/1900 12:00:00 PM


but i need data to be displayed in field 1 as 2/12/2006
and in field 2 as 10:30.


can anybody tell me how to do this. its very urgent for me.


thanx in advacne

yoshitha
 
Y

yoshitha

thanx Justin, it isworking i just modified like this
DataFormatString="{0:H:mm}", now it is showing the way i needed.
Regards
Yoshitha

S. Justin Gengo said:
Yoshitha,

Sure can!

Use uppercase "H" only for a 24-hour clock, and lowercase "h" only for a
12-hour clock. The AM/PM formats are replaced with "t" and "tt."

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
i used the follwoing statement in data grid
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

then it is showing time in 12 hours format but i want to display it as 24
hours format.
for eg in data base the data is stored as 18:30

and after using the above statement in the grid it is displaying 6:30
can you tell me how to display in 24 hours format?



S. Justin Gengo said:
Yoshitha,

You'll only need one field in the database. The database's DateTime
field is always a combination of date and time. You should store your
values as a single datetime (SQL Server 2005 was supposed to include
separate date and time fields but they were removed from the final
release....).

When you store your date and time in the server just combine them:

Dim MyDate As New DateTime([Year], [Month], [Day], [Hour], [Minute],
[Seconds])

SqlCommand1.Parameters.Add("@Date", Data.SqlDbType.DateTime).Value =
MyDate

Then in your datagrid use string formatting to display just the portion
you want:

(You say your using a datagrid so I assume you're using .NET 1.1?)

<asp:BoundColumn DataField="CreateDate" HeaderText="Date"
DataFormatString="{0:d}">
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

Using the dataformat string you may display just the short date
(lowercase "d") and just the short time (lowercase "t") of the datetime
column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
hi

db : sql server 2000
lan : C#.net(ASp.Net)

in my database table there are 2 fileds of data type datatime.

in field 1 i'm storing date

in field 2 i'm storing time.

in my textbox date is in the format of 2/12/2006 and i'm inserting as
it

is.

and time is in teh fromat of 10:30 and i'm inserting as it is.

but after retrieving and displaying in data grid it is diplsying the

filed 1 like this.

2/12/2006 12:00:00 AM

and field is displaying like this.

1/1/1900 12:00:00 PM


but i need data to be displayed in field 1 as 2/12/2006
and in field 2 as 10:30.


can anybody tell me how to do this. its very urgent for me.


thanx in advacne

yoshitha
 
S

S. Justin Gengo [MCP]

Yoshitha,

Great!

Happy coding!

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
thanx Justin, it isworking i just modified like this
DataFormatString="{0:H:mm}", now it is showing the way i needed.
Regards
Yoshitha

S. Justin Gengo said:
Yoshitha,

Sure can!

Use uppercase "H" only for a 24-hour clock, and lowercase "h" only for a
12-hour clock. The AM/PM formats are replaced with "t" and "tt."

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
yoshitha said:
i used the follwoing statement in data grid
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

then it is showing time in 12 hours format but i want to display it as
24 hours format.
for eg in data base the data is stored as 18:30

and after using the above statement in the grid it is displaying 6:30
can you tell me how to display in 24 hours format?



"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>
wrote in message Yoshitha,

You'll only need one field in the database. The database's DateTime
field is always a combination of date and time. You should store your
values as a single datetime (SQL Server 2005 was supposed to include
separate date and time fields but they were removed from the final
release....).

When you store your date and time in the server just combine them:

Dim MyDate As New DateTime([Year], [Month], [Day], [Hour], [Minute],
[Seconds])

SqlCommand1.Parameters.Add("@Date", Data.SqlDbType.DateTime).Value =
MyDate

Then in your datagrid use string formatting to display just the portion
you want:

(You say your using a datagrid so I assume you're using .NET 1.1?)

<asp:BoundColumn DataField="CreateDate" HeaderText="Date"
DataFormatString="{0:d}">
<asp:BoundColumn DataField="CreateDate" HeaderText="Time"
DataFormatString="{0:t">

Using the dataformat string you may display just the short date
(lowercase "d") and just the short time (lowercase "t") of the datetime
column.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
hi

db : sql server 2000
lan : C#.net(ASp.Net)

in my database table there are 2 fileds of data type datatime.

in field 1 i'm storing date

in field 2 i'm storing time.

in my textbox date is in the format of 2/12/2006 and i'm inserting as
it

is.

and time is in teh fromat of 10:30 and i'm inserting as it is.

but after retrieving and displaying in data grid it is diplsying the

filed 1 like this.

2/12/2006 12:00:00 AM

and field is displaying like this.

1/1/1900 12:00:00 PM


but i need data to be displayed in field 1 as 2/12/2006
and in field 2 as 10:30.


can anybody tell me how to do this. its very urgent for me.


thanx in advacne

yoshitha
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top