User login

  

Date & Time Functions

The following lists alphabetically built-in functions available for working with date and time.

These functions are placed in DateTime package.

 CompareDates GetDate Month
 CompareTime GetShortYear Now
 DateValue GetTicks Seconds
 Day GetTime TimeValue
 DayOfWeek Hour Year
 DayOfYear Minute 

 

Java time and .Net time

The application based on Java platform use the January 1, 1970 00:00:00.000 GMT as start point for calc time. It likes Unix/Linux system time or many other platforms (example, MQL4). But, MS .Net (and so PTL Builder) uses  the January 1, 0001 00:00:00.000 GMT as start point for calc time. So, the Java time must be converted with special functions for correct applied in .Net application.

 

CompareDates

Compares two dates and returns 0 if they are the same, -1 if the first one is earlier than the first one, and 1 if the first one is later.

Syntax

int CompareDates( datetime date1, datetime date2)

Parameters

  • date1 - Any datetime value.
  • date2 - Any datetime value.

Example

int n;

n = CompareDates( AddYears(Now(), 2), Now());         // n <- 1

n = CompareDates ( AddMinutes(Now(), 2), Now());      // n <- 0

 

CompareTime

Compares two time values and returns 0 if they are the same, -1 if the first one is earlier than the first one, and 1 if the first one is later.

Syntax

int CompareTime( datetime time1, datetime time1)

Parameters

  • time1 - Any datetime value.
  • time2 - Any datetime value.

Example

int n;

n = CompareTime( AddYears(Now(), 2), Now());       // n <- 0

n = CompareTime( AddMinutes(Now(), 2), Now());     // n <- 1

 

DateValue

Returns the datetime value for specific year, month and day.

Syntax

double DateValue(int year, int month, int day)

 

Day

Returns the day of month for current locale time

Syntax

int Day()

Parameters

None

Example

int dt;

dt = Day();   // dt <- 25  for April 25

dt = Day();   // dt <- 8  for June 8

 

DayOfWeek

Returns the day of week for current locale time, BUT the first day of week is SUNDAY

Syntax

int DayOfWeek()

Example

int dt;

dt = DayOfWeek();   // dt <- 6  for Friday, April 25 2008

dt = DayOfWeek();   // dt <- 4  for Wednesday, June 25 2008

 

DayOfYear

Returns the day of year for current locale time.

Syntax

int DayOfYear()

 

Example

int dt;

dt = DayOfYear(Now());   

 

GetDate

Returns the date from the datetime value.

Syntax

datetime GetDate( datetime dateTime)

Parameters

  • dateTime - Any datetime value.

Example

int dt;

dt = GetDate(Now());

 


GetShortYear

Returns the current year in short representation.

Syntax

int GetShortYear()

Parameters

none

Example

int dt;

dt = GetShortYear();

 

GetTicks

Returns the ticks from Jan 1, 1970 as double.

Syntax

double GetTicks()

Example

double dt;

dt = GetTicks();

 

GetTime

Returns the time for specified value.

Syntax

datetime GetTime( datetime dateTime)

Parameters

  • dateTimeAny - datetime value.

Example

datetime dt;

dt = GetTime( Now() );     // n <- 483696875000 for 633447267696875000

 

Hour

Returns the hours for current locale time

Syntax

int Hour()

Parameters

None

Example

int dt;

dt = Hour();   // dt <- 10  for 10 Hours

 

Minute

Returns the minutes for current locale time

Syntax

int Minute()

Parameters

None

Example

int dt;

dt = Minute();   // dt <- 33  for 33 Minutes

 

Month

Returns the months of year for current date

Syntax

int Month()

Parameters

  • year - Any numeric value that represents Java time in milliseconds

Example

double dt;

dt = Month();   

 

Now

Function returns datetime value as a milliseconds value represents the number of milliseconds that have passed since January 1, 0001 year 00:00:00.000 GMT (.Net time).

Syntax

datetime Now()

 

Example

datetime dt;

dt = Now();  

 

Seconds

Returns the seconds for current locale time

Syntax

int Seconds()

 

Example

double dt;

dt = Seconds();   // dt <- 33  for 33 seconds

 

TimeValue

Function creates and returns datetime value as a milliseconds value represents the number of milliseconds that have passed since January 1, 0001 year 00:00:00.000 GMT (.Net time).

Syntax

datetime TimeValue( int year, int month, int day, int hour, int minute, int second)

Parameters

  • year - Any datetime value.
  • month - Any datetime value.
  • day - Any datetime value.
  • hour - Any datetime value.
  • minute - Any datetime value.
  • second - Any datetime value.

Example

datetime dt;

dt = TimeValue(2008, 7, 4, 12, 0, 0);   // dt <- 633507696000000000

 

Year

Returns the year for current locale time

Syntax

int Year()

Parameters

None

Example

int dt;

dt = Year();   // dt <- 2008  for 2008 year

12345