# How to check time?

228

Hi, I need to check the time is between midnight and 12:05 (GMT +2) in an IF statement.

How could I do this??

Thanks, sam.

3243

228

Thanks...

So would

if ( TimeLocal() >= '00:00:00' && TimeLocal() <= '00:05:00')

work?

Im new to this, cant get my head around the time functions and order functions.

Sam.

Moderator
18024

samuelgo:

Thanks...

So would

if ( TimeLocal() >= '00:00:00' && TimeLocal() <= '00:05:00')

work?

Im new to this, cant get my head around the time functions and order functions.

Sam.

The time functions return a datetime type variable (number of seconds since 1/1/70) so you should convert your midnight and midnight:05 times to datetimes,  have a read of this:  Midnight
228

Thanks!
15574

 samuelgo: I need to check the time is between midnight and 12:05 (GMT +2) in an IF statement. ```#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600 int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();                                           return( when % HR2400 );            } datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();                                           return( when - TimeOfDay(when) );   } //datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent(); //                                          return(DateOfDay(when) + HR2400);   } //datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent(); //   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1); //                                       return( iTime(NULL, PERIOD_D1, iD1) ); } : #define HR0005 300 // 12:05 AM datetime now = TimeCurrent(); // or local or gmt if(TimeOfDay(now) < HR0005) ...```
Moderator
2333

It's not particularly elegant, but I use the following to get midnight of the current date (or whichever date you wish to substitute):

```   datetime Midnight = (datetime)TimeToStr(TimeCurrent(),TIME_DATE);
```