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

How do I subtract 1 hour from DATETIME string using timespan instance

CODE:
DateTime coursestatusdate = DateTime.MinValue;
if (courseRow["coursestatusdate"].ToString() != string.Empty)
{
coursestatusdate = DateTime.Parse(courseRow
["coursestatusdate"].ToString());
//TODO: Convert coursestatusdate to CST
DateTime courseStatusDateCentralTime =
coursestatusdate.Add(System.TimeSpan.FromHours(-1));
}

I need to preserve the time for coursestatusdate, and I need courseStatusDateCentralTime to reflect : coursestatusdate - 1 hour
Nov 23 '09 #1
2 4111
I was almost there. All I had to do was uncomment my declaration, and removed the DATE TIME from my conversion. ...all is well.

private void Update_Course(DataRowView courseRow, DataRow studentRow, DataView courseDV)
{
DateTime courseStatusDateCentralTime = DateTime.MinValue;
DateTime coursestatusdate = DateTime.MinValue;

if (courseRow["coursestatusdate"].ToString() != string.Empty)
{
coursestatusdate = DateTime.Parse(courseRow["coursestatusdate"].ToString());
//TODO: Convert coursestatusdate to CST
courseStatusDateCentralTime = coursestatusdate.Add(System.TimeSpan.FromHours(-1));
}
Nov 23 '09 #2
GaryTexmo
1,501 Expert 1GB
http://msdn.microsoft.com/en-us/libr....datetime.aspx

I think you need the AddHours method.

Expand|Select|Wrap|Line Numbers
  1.             DateTime now = DateTime.Now;
  2.             DateTime nowMinusOne = now.AddHours(-1);
  3.  
  4.             Console.WriteLine(now.ToString());
  5.             Console.WriteLine(nowMinusOne.ToString());
By the way, I notice you're talking about timezones in there... a handy tip if you're going to do any compares. There's a ToUniversalTime method off a DateTime object that will convert a time to universal time. I don't now if you know about it already, but I discovered it recently so maybe it will save you some trouble in the future :)

*Edit: Looks like you got got it another way, nice work!
Nov 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Russ Green | last post by:
I'm trying to perform several manipulations to time values (all will be stored in a access database). I need to find the elapsed time between a start time and a finish time and I also need to be...
7
by: Jimbo | last post by:
Anyone know how I can subtract 12 months from the current date?
2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
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" ...
4
by: Lee | last post by:
Hi All, I have a datetime field and want to subtract 24 (or any other number of) hours from it. How would I go about this? Thanks Lee
4
by: DWW | last post by:
System.DateTime returns a string with the date and time. I want to convert the time to an integer, for example, convert 10:24:45 to 102445. Much research has turned up a myriad of variations on...
5
by: Nikeman | last post by:
good day, I simply would like to know as to how I can parse seconds to convert them into equivalent DateTime representation. To be more persice, I have a DirectShow app written in VB.NET, with a...
2
by: elena | last post by:
Hi, All Please, i need help with cast string to DateTime: DateTime dt = new DateTime(2006,09,17); it works i can update Field in Access DB Next field is Short Time data type, how i can cast...
1
by: =?Utf-8?B?RGFwcGVyRGFuSEBub3NwYW0ubm9zcGFt?= | last post by:
Given the example below, can someone explain why TimeSpan.TotalDays gives a different result than subtracting 2 DateTime.ToOADates? I am completely stumped. Thanks in advance, Dan Example...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...
0
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...
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...

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.