473,404 Members | 2,179 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,404 software developers and data experts.

DateTime display in a datagrid?

Hello,

I am importing a flat text file, and putting it into a datagrid for display
on a form.

Currently the users have their dates and times seperated. I have two
fields, therefore in the datatable feeding the datagrid control. Both are of
the DateTime Type. How do I get the time field to display only the Time, and
not the date, which is apparently the default.

As a followup, how do I get one DateTime value to display both the date and
the time in a datagrid Control?

Thanks in advance,

Andrew S. Giles
Nov 17 '05 #1
3 4218
"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
Hello,

I am importing a flat text file, and putting it into a datagrid for
display
on a form.

Currently the users have their dates and times seperated. I have two
fields, therefore in the datatable feeding the datagrid control. Both are
of
the DateTime Type. How do I get the time field to display only the Time,
and
not the date, which is apparently the default.
Use DateTime.ToShartTimeString() or DateTime.ToLongTimeString().
As a followup, how do I get one DateTime value to display both the date
and
the time in a datagrid Control?
You'll have to create a new DateTime object combining the relevant
properties of the two existing DateTime objects. For example, let's assume
your two existing DateTime objects are called dtDate (the date) and dtTime
(the time in hours, minutes, seconds):

DateTime dtCombined = new DateTime(dtDate.Year, dtDate.Month, dtDate.Day);
dtCombined = dtCombined + new TimeSpan(dtTime.Hour, dtTime.Minute,
dtTime.Second);

In case I misunderstood your question, and you simply want to display both
date and time of one and the same DateTime object, simply use
DateTime.ToString().
Thanks in advance,

Andrew S. Giles

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 17 '05 #2
Kia,

Thanks! I have the data into the DateTime controls. My problem is that
when I put the DateTime object into the datatable that is the source for the
datagrid, all that is displayed is the Date of the DateTime, not the date and
time, or just the time.

How do I get the time to be displayed after the date, if the datatype in the
datagrid is DateTime?

Andrew

"Kai Brinkmann [MSFT]" wrote:
"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
Hello,

I am importing a flat text file, and putting it into a datagrid for
display
on a form.

Currently the users have their dates and times seperated. I have two
fields, therefore in the datatable feeding the datagrid control. Both are
of
the DateTime Type. How do I get the time field to display only the Time,
and
not the date, which is apparently the default.


Use DateTime.ToShartTimeString() or DateTime.ToLongTimeString().
As a followup, how do I get one DateTime value to display both the date
and
the time in a datagrid Control?


You'll have to create a new DateTime object combining the relevant
properties of the two existing DateTime objects. For example, let's assume
your two existing DateTime objects are called dtDate (the date) and dtTime
(the time in hours, minutes, seconds):

DateTime dtCombined = new DateTime(dtDate.Year, dtDate.Month, dtDate.Day);
dtCombined = dtCombined + new TimeSpan(dtTime.Hour, dtTime.Minute,
dtTime.Second);

In case I misunderstood your question, and you simply want to display both
date and time of one and the same DateTime object, simply use
DateTime.ToString().
Thanks in advance,

Andrew S. Giles

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 17 '05 #3
Ah, now I understand what you're asking :) You must forgive me for being a
little dense today; my weekend wasn't as relaxing as I had hoped...

Personally, I think by far the easiest way to address this issue would be to
change the data type of the approprivate column in your DataTable from
System.DateTime to System.String. Then store DateTime.ToString() in this
column (default format is MM/DD/YYYY HH:MM:SS AM/PM; but if you don't like
that you can use a format provider). Now when you bind your DataTable to the
DataGrid you'll see the expected data.

If you need to, you can then use DateTime.Parse(System.String) to turn the
value in the DataTable back into a DateTime object for processing.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Kia,

Thanks! I have the data into the DateTime controls. My problem is that
when I put the DateTime object into the datatable that is the source for
the
datagrid, all that is displayed is the Date of the DateTime, not the date
and
time, or just the time.

How do I get the time to be displayed after the date, if the datatype in
the
datagrid is DateTime?

Andrew

"Kai Brinkmann [MSFT]" wrote:
"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in
message
news:89**********************************@microsof t.com...
> Hello,
>
> I am importing a flat text file, and putting it into a datagrid for
> display
> on a form.
>
> Currently the users have their dates and times seperated. I have two
> fields, therefore in the datatable feeding the datagrid control. Both
> are
> of
> the DateTime Type. How do I get the time field to display only the
> Time,
> and
> not the date, which is apparently the default.


Use DateTime.ToShartTimeString() or DateTime.ToLongTimeString().
> As a followup, how do I get one DateTime value to display both the date
> and
> the time in a datagrid Control?


You'll have to create a new DateTime object combining the relevant
properties of the two existing DateTime objects. For example, let's
assume
your two existing DateTime objects are called dtDate (the date) and
dtTime
(the time in hours, minutes, seconds):

DateTime dtCombined = new DateTime(dtDate.Year, dtDate.Month,
dtDate.Day);
dtCombined = dtCombined + new TimeSpan(dtTime.Hour, dtTime.Minute,
dtTime.Second);

In case I misunderstood your question, and you simply want to display
both
date and time of one and the same DateTime object, simply use
DateTime.ToString().
> Thanks in advance,
>
> Andrew S. Giles

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 17 '05 #4

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

Similar topics

1
by: D. Shane Fowlkes | last post by:
I have a DataGrid which is populated by a DataBind command and is bound to a DataSet. It displays nicely on the page and all is well. Is it even possible to have one of the "columns" filled with...
2
by: Mike | last post by:
How can i get the datagrid to appear within my web page without using a DB? Currently I'm creating some screen mock ups and want the datagrid to appear within the browser without connecting to a...
1
by: Danny Ni | last post by:
Hi, Is there a way to selectively display content of a DataGrid or DataList? Normally I bind them to datareader or datatable, and they will display all the rows, what if I don't want to display...
1
by: Agnes | last post by:
I give up the 'dd-mm-yyyy' bindign question. However, how can i make the text box display date without time ??? Thank
5
by: Raju5725 | last post by:
Hi All, I need some help. My database is in MS-ACCESS, one of the field type is Date/Time, when I am trying to fill the records into data grid and show to the user by using windows application...
1
by: Untitled | last post by:
I have an application that stores all DateTime inforamtion in UTC. However, this application will be accessed from arround the world. I would like my users to be able to specify their prefered...
2
by: arunkumaryespee | last post by:
Hii i have a problem in display a empty datagrid with header during page_load(). actually i use the datagrid for searching purpose. During the page load i want to display an empty grid with...
6
by: Marcin Wiszowaty | last post by:
Hello, I am reading into a dataset through a dataadapter. All drag+drop implementation. I have a field in the db that is a datetime(8). whenever i readin this field the datagrid displays the...
0
by: kashif73 | last post by:
IS it possible to display my data grid vertically in VB.NET? I mean my table columns display vertically on the left & rows horizontally in place of columns?
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.