# Problem solving in programming

1809

Hi Can someone please solve the following problem for me? :)

```      string delay="00:10";
datetime    time=(datetime)PositionGetInteger(POSITION_TIME)+StringToTime(delay);
printf(" open order Position  "+(datetime)PositionGetInteger(POSITION_TIME));
printf(" time : "+time );```

output :

2013.12.28 08:27:52    Core 1    2013.09.04 13:58:40    time : 2057.05.08 13:10:00

2013.12.28 08:27:52    Core 1    2013.09.04 13:58:40    open order Position  2013.09.04 13:00:00

Moderator
4339

It looks like that the StringToTime() function doesn't accept the format of "00:10", you may check out the function's reference in the Documentation section.

If the "00:10" means 10 seconds, you may simply write the code as:

`datetime time = (datetime)PositionGetInteger(POSITION_TIME)+(datetime)10;`
1809

forex2start:

It looks like that the StringToTime() function doesn't accept the format of "00:10", you may check out the function's reference in the Documentation section.

If the "00:10" means 10 seconds, you may simply write the code as:

thnx for relpay

but i want used delay

`string delay="00:10";`
Moderator
33504

niloufar:

Hi Can someone please solve the following problem for me? :)

output :

2013.12.28 08:27:52    Core 1    2013.09.04 13:58:40    time : 2057.05.08 13:10:00

2013.12.28 08:27:52    Core 1    2013.09.04 13:58:40    open order Position  2013.09.04 13:00:00

It's because

`   string delay="00:10";`

when converted to a datetime gives you :

2013.12.20 10:21:59.930    SomeTests (EURUSD,H1)    delay = 2013.12.20 00:10:00

The function converts a string containing time or date in "yyyy.mm.dd [hh:mi]" format into datetime type.

So if you want absolutely to proceed this way, you have to use :

`   string delay="1970.01.01 00:10";`
483

"Time" can have 2 different meanings: position and duration.

StringToTime() accept a string that represent a position in time (a particular moment) and not a duration/delay.

datetime data-type store seconds, so if you want to add your delay to a date, first you need to have its value in seconds.

If you want to represent a delay with the format HH:MM (hours : minutes), you need to extract from it the minutes substring with StringSubstr()

then convert it to integer with StringToInteger(), convert to seconds and add this value to your POSITION_TIME.

Something like this: (simplified)

`StringToInteger(StringSubstr("00:10",3,2))*60`

MQL5 Programming Basics: Time
• 2013.04.26
• Dmitry Fedoseev
• www.mql5.com
Introduction MQL5 offers a number of simple functions for working with time and you should not find it difficult getting familiar with them. The range of tasks that require use of date and time is quite small. The main tasks are: To perform certain actions at a given point of time (Fig. 1). These may be actions performed at the same time...