Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I convert a DateTime table column to a TimeSpan or DayOfWeek ?

Thread Tools

How do I convert a DateTime table column to a TimeSpan or DayOfWeek ?

Harry Haller
Posts: n/a
The context is shown below in the getGames() method.

I get errors on these lines:

dtGames.Rows[i]["playTime"] = (TimeSpan)dtGames.Rows[i]["playDate"];
dtGames.Rows[i]["playDay"] = (DayOfWeek)dtGames.Rows[i]["playDate"];

because the playDate column is a DateTime.

Here is my solution but I don't like it. What else can I do?

dtGames.Rows[i]["playTime"] =
dtGames.Rows[i]["playDay"] =

public DataView getGames()
DataTable dtGames = DAL.GetTable("Games");
DataColumn colItem;

colItem = new DataColumn("playTime",

colItem = new DataColumn("playDay",

for (int i = 0; i <= dtGames.Rows.Count - 1; i++)
dtGames.Rows[i]["playTime"] =
dtGames.Rows[i]["playDay"] =

dvwGames = dtGames.DefaultView;
Cache.Insert("Games", dvwGames);
return dvwGames;

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM