473,659 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)dtGam es.Rows[i]["playDate"];
dtGames.Rows[i]["playDay"] = (DayOfWeek)dtGa mes.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.ToDateT ime(dtGames.Row s[i]["playDate"]).TimeOfDay;
dtGames.Rows[i]["playDay"] =
Convert.ToDateT ime(dtGames.Row s[i]["playDate"]).DayOfWeek;
public DataView getGames()
{
DataTable dtGames = DAL.GetTable("G ames");
DataColumn colItem;

colItem = new DataColumn("pla yTime",
Type.GetType("S ystem.TimeSpan" ));
dtGames.Columns .Add(colItem);

colItem = new DataColumn("pla yDay",
Type.GetType("S ystem.DayOfWeek "));
dtGames.Columns .Add(colItem);

for (int i = 0; i <= dtGames.Rows.Co unt - 1; i++)
{
dtGames.Rows[i]["playTime"] =
(TimeSpan)dtGam es.Rows[i]["playDate"];
dtGames.Rows[i]["playDay"] =
(DayOfWeek)dtGa mes.Rows[i]["playDate"];
}

dvwGames = dtGames.Default View;
Cache.Insert("G ames", dvwGames);
return dvwGames;
}

Nov 19 '05 #1
0 1791

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

Similar topics

2
1712
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 given time on any given day. ne1? ~Gordon
15
14268
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" DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
2
18854
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
5789
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 what it would currently be in Pacific time. Taking in account Daylight Savings Time Thanks, Ed,
6
1539
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
4625
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 mail if the sever has a scheduled downtime say, Sunday at 23:00 for 4 hrs. Is there an easy way to see if the current time is within that window? Thanks
2
4873
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 any wrapping): if ((dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Saturday) && (dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Sunday)) { ...
3
6344
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 all, I have been unable to use the mid() function like I did in vb 6.
0
16490
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 formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.