# Getting current date without time

5536

Hi

I'm trying to get the current date without the time using this code

```MqlDateTime Time;
TimeCurrent(Time);

string CurrDate = IntegerToString(Time.year) + "." + IntegerToString(Time.mon) + "." + IntegerToString(Time.day);

HistorySelect(StringToTime(CurrDate), TimeCurrent());```

are there any simpler ways of getting the current date only?

2181

doshur:

Hi

I'm trying to get the current date without the time using this code

are there any simpler ways of getting the current date only?

Does using CopyTime with PERIOD_D1 helps ?
5536

phi.nuts:
Does using CopyTime with PERIOD_D1 helps ?
Can give me an example how to extract current date from copytime?
2181

doshur:
Can give me an example how to extract current date from copytime?

Sample ? I thought you can do this yourself ;D

```  datetime dt1[1];

if (CopyTime (_Symbol, PERIOD_D1, 0, 1, dt1) == 1)
{
Print(TimeToString (dt1 [0], TIME_DATE| TIME_SECONDS));
}```

The problem with your first code is this : when using today date March 04, 2013, your code returned string 2013.3.4, while it should be string 2013.03.04.

5536

phi.nuts:

Sample ? I thought you can do this yourself ;D

The problem with your first code is this : when using today date March 04, 2013, your code returned string 2013.3.4, while it should be string 2013.03.04.

Thanks for the comment.

Other than copytime is there any other methods?

2181

doshur:

Thanks for the comment.

Other than copytime is there any other methods?

Yes, it's called LOL ...

```string LOL = TimeToString (TimeCurrent(), TIME_DATE);
Print (StringToTime(LOL));```

being lazy is no good, doshur ;D

5536

phi.nuts:

Yes, it's called LOL ...

being lazy is no good, doshur ;D

This seems to be much better. Appreciate the keywords and sample.
5536

this is the reason why i asked this question. to develop one trade a day code. i can easily use new bar tactics but if EA got restarted, it will trade again.

here u go...

```   static bool OneTrade;

string CurrDate = TimeToString(TimeCurrent(), TIME_DATE);

HistorySelect(StringToTime(CurrDate), TimeCurrent());

for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
{
Ticket = HistoryDealGetTicket(i);
Entry  = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

if(Entry == DEAL_ENTRY_IN)
{
}
}```

5536

oops, i forgot to add a break to the loop if conditions is found true.
Moderator
18047

doshur:

this is the reason why i asked this question. to develop one trade a day code. i can easily use new bar tactics but if EA got restarted, it will trade again.

here u go...

You can also remove the messing about with strings stuff . . .

```#define SECONDSINADAY  86400

datetime Midnight, StartOfNewYear;

Midnight = TimeCurrent() - ( TimeCurrent()%SECONDSINADAY );  // midnight today as a datetime

HistorySelect(Midnight, TimeCurrent());            // just history between Midnight and now

for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
{
Ticket = HistoryDealGetTicket(i);
Entry  = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

if(Entry == DEAL_ENTRY_IN)
{
}
}```
5536

RaptorUK:

You can also remove the messing about with strings stuff . . .

let me compress the code a little

```   static bool OneTrade;

HistorySelect(TimeCurrent() - (TimeCurrent()%86400), TimeCurrent());   // just history between Midnight and now

for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
{
Ticket = HistoryDealGetTicket(i);
Entry  = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

if(Entry == DEAL_ENTRY_IN)
{