Hi all, I want to create an automatic expiration datetime instead of my usual method of counters and checks. My question is: given datetime CurrTime = blahblah, how do I create datetime ExpTime = CurrTime + x minutes? I looked at the doc to try and figure out how to create a datetime, but it only lists static examples, which are useless to any programmer. Knowing how to concatenate elements of datetime would be nice. If we knew that, we could simply do TimeMinute(CurrTime), etc., and add the time shift. Unfortunately I also don't know how to do that.
All this makes it very easy to do date arithmetic involving any period up to and including a number of weeks, but makes it relatively hard to do addition or subtraction of months, or to construct the datetime value for a specific day, month, and year.
Ah, okay. Thanks. That explains why something like datetime x = 0; is valid. Why not just use an int? Clarity? Or maybe to include the ability to easily specify a date using the D'' format?
I suppose to construct a specific day, month, and year, you would need to identify how many leap years there were between the specified year and 1970. From there, wouldn't it be a simple matter of multiplying 60 * NumDaysFrom1970?
I suppose to construct a specific day, month, and year, you would need to identify how many leap years there were between the specified year and 1970. From there, wouldn't it be a simple matter of multiplying 60 * NumDaysFrom1970?
It's a bit crazy, but it's easiest to do it via the StrToTime() function (which is very forgiving about formats and separators). For example:
int day = 8; int month = 7; int year = 2010; int hour = 11; int minute = 38; int second = 0; string strTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second; datetime whatever = StrToTime(strTime);
I use StrToTime in init() once. And use datetime like integer in iteration loop. See the example indy in this post.
I suppose to construct a specific day, month, and year, you would need to identify how many leap years there were between the specified year and 1970. From there, wouldn't it be a simple matter of multiplying 60 * NumDaysFrom1970?
The method you mentioned is used by Kim-IV here. HTH.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all, I want to create an automatic expiration datetime instead of my usual method of counters and checks. My question is: given datetime CurrTime = blahblah, how do I create datetime ExpTime = CurrTime + x minutes? I looked at the doc to try and figure out how to create a datetime, but it only lists static examples, which are useless to any programmer. Knowing how to concatenate elements of datetime would be nice. If we knew that, we could simply do TimeMinute(CurrTime), etc., and add the time shift. Unfortunately I also don't know how to do that.
Thanks in advance for help. =)