Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 07-21-2005, 12:35 PM   #1
Default How do I convert a DateTime table column to a TimeSpan or DayOfWeek ?


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"] =
Convert.ToDateTime(dtGames.Rows[i]["playDate"]).TimeOfDay;
dtGames.Rows[i]["playDay"] =
Convert.ToDateTime(dtGames.Rows[i]["playDate"]).DayOfWeek;


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

colItem = new DataColumn("playTime",
Type.GetType("System.TimeSpan"));
dtGames.Columns.Add(colItem);

colItem = new DataColumn("playDay",
Type.GetType("System.DayOfWeek"));
dtGames.Columns.Add(colItem);

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

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



Harry Haller
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Rip DVD and Convert Video on Mac OS dave345 Media 12 07-07-2008 09:32 AM
MCITP and stored procedure permissions Darrilgibson@gmail.com MCITP 5 06-07-2008 12:37 PM
Guide-how to choose the most satisfactory software to convert DVD to your mobile devices bobo DVD Video 0 08-07-2006 03:01 AM
How to convert DVD/Video to iPod/PSP? ivan DVD Video 0 04-12-2006 09:25 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46