How to add TimeSpan to a DatTime
-
Hi all, I want to add a TimeSpan, in milliseconds into DateTime variable. I've try this.
DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp));
For different calTimeStamp give the same value, that is dtStart as the output. No time is added there. Can you someone tell me where I'm going wrong. Thanks
I appreciate your help all the time... CodingLover :)
-
Hi all, I want to add a TimeSpan, in milliseconds into DateTime variable. I've try this.
DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp));
For different calTimeStamp give the same value, that is dtStart as the output. No time is added there. Can you someone tell me where I'm going wrong. Thanks
I appreciate your help all the time... CodingLover :)
1. There is an extra closing bracket. 2. As DateTime is struct dtStart will not change but da will store result of the addition.
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion
-
Hi all, I want to add a TimeSpan, in milliseconds into DateTime variable. I've try this.
DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp));
For different calTimeStamp give the same value, that is dtStart as the output. No time is added there. Can you someone tell me where I'm going wrong. Thanks
I appreciate your help all the time... CodingLover :)
Two things: 1) Make sure calTimeStamp does not equal zero because the following works fine for me: int calTimeStamp = 30; //so that I know I have a value DateTime dtStart = DateTime.Now; //I need a start time DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp); //this adds 30 seconds to dtStart 2) Using TimeSpan(0, 0, variable) gives you seconds not milliseconds. For milliseconds you have to use TimeSpan(days, hours, seconds, milliseconds);
-
Hi all, I want to add a TimeSpan, in milliseconds into DateTime variable. I've try this.
DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp));
For different calTimeStamp give the same value, that is dtStart as the output. No time is added there. Can you someone tell me where I'm going wrong. Thanks
I appreciate your help all the time... CodingLover :)
Is calTimeStamp the number of milliseconds , seconds, or minutes? It looks like it's seconds based on the constructor overload you used. (Your variable names kinda suck.) I always use the last overload so that there's no question about what the value represents.
DateTime da = dtStart.Add(new TimeSpan(0,0,0,calTimeStamp,0));
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
1. There is an extra closing bracket. 2. As DateTime is struct dtStart will not change but da will store result of the addition.
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion
Ya, that bracket is added by mistake. Sorry about that.
I appreciate your help all the time... CodingLover :)
-
Two things: 1) Make sure calTimeStamp does not equal zero because the following works fine for me: int calTimeStamp = 30; //so that I know I have a value DateTime dtStart = DateTime.Now; //I need a start time DateTime da = dtStart + new TimeSpan(0, 0, calTimeStamp); //this adds 30 seconds to dtStart 2) Using TimeSpan(0, 0, variable) gives you seconds not milliseconds. For milliseconds you have to use TimeSpan(days, hours, seconds, milliseconds);
David Fleming wrote:
- Make sure calTimeStamp does not equal zero because the following works fine for me:
Yep, this is the issue. I'm doing this process in a loop and each time calTimeStamp set to zero.
I appreciate your help all the time... CodingLover :)
-
Ya, that bracket is added by mistake. Sorry about that.
I appreciate your help all the time... CodingLover :)
Glad to help you :)
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion