How do I get the timestamp of 'NOW()', i.e. what is the TIME this instant upon execution of this line of code?
https://www.mql5.com/en/docs/constants/structures/mqldatetime
MqlDateTime mdt; TimeCurrent(mdt);
- www.mql5.com
I want to be able to print the timestamp something like this:
Print("The time this instant is "+FormatString("%Y-%M-%D %h:%mm:%ss.%uuu",NOW()));
- Do you actually have to have that exact format? You are making a lot of work for yourself.
- You have to convert NOW() to its parts as Lippmaje says. Or convert it to a string and then select the appropriate parts
- Then format it to your output format.
- Or just use
TimeToString(NOW(), TIME_DATE|TIME_MINUTES|TIME_SECONDS)
and get "yyyy.mm.dd hh:mi:ss" format. - Either case datetimes have no fraction of a second, you can't get that.
TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
TimeCurrent() returns the time of the last tick. So all logs within the same OnTick will have the same value. Use GetMicrosecondCount() instead.
- Do you actually have to have that exact format? You are making a lot of work for yourself.
- You have to convert NOW() to its parts as Lippmaje says. Or convert it to a string and then select the appropriate parts
- Then format it to your output format.
- Or just use and get "yyyy.mm.dd hh:mi:ss" format.
- Either case datetimes have no fraction of a second, you can't get that.
Thanks. It's just for debugging, and also learning. "NOW()" is just what it's called in Excel. I'm getting my head around how and when things are executed in MQL.
Thanks. It's just for debugging, and also learning. "NOW()" is just what it's called in Excel. I'm getting my head around how and when things are executed in MQL.
- www.mql5.com
I want to be able to print the timestamp something like this:
To be clear, I want to print the exact time stamp of when this Print function is run, for debugging purposes. I want to insert this into my code at different points so I can understand when something was run.
Thanks.