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

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;
}

Nov 19 '05 #1
0 1781

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

Similar topics

2
by: Simple Simon | last post by:
Hi all, I'm struggling with an elegant way to figure out if a DateTime falls between any Firday @ 6pm and Sunday @ 9pm. For example: If i want to fax a message b/w Fri 6pm and Sun 9pm on any...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
2
by: Chris | last post by:
Hello, How can i convert a C++ CTime (4 bytes) into a C# DateTime ? (my CTime is read in a file). Thanks, -- Chris
5
by: ECVerify.com | last post by:
I am trying to convert a computers local time to Pacific time, I can get it back to UTC pretty easy but I actually want to convert whatever the local time is on the computer I want to calculate...
6
by: Mike | last post by:
I'm getting my data from my database in seconds, 3600, how can i convert that to time such as 1:00 pm?
8
by: ajs | last post by:
I have a process that verifies that a server is running. If the server stops responding I send an email to a support person. Now I want to add a downtime indicator so that my code does not send...
2
by: David P. Donahue | last post by:
Probably a simple question: I have a function that receives as an argument a DateTime value. One of the things I want to do is check to see if it's a weekday. So I do the following (sorry for...
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.