Difference between revisions of "Outputting Dates in EasyLanguage"

From MultiCharts
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
This article gives some tips and examples for outputting dates in [[:Category:EasyLanguage|EasyLanguage]].
+
This article gives some tips and examples for outputting dates in [[:Category:About_EasyLanguage|EasyLanguage]].
  
http://www.buyxanaxonlinepill.com/ order xanax online - order xanax cheap
+
== Relevant EasyLanguage Date reserved words ==
 +
 
 +
Just as a reminder, the following Date reserved words are often used in working with dates:
 +
 
 +
* <code><b>[[Date]]</b></code>, which returns the Date of the current bar in ''YYYMMdd'' format. This date format is always the format with which a date calculation starts.  
 +
* <code><b>[[CurrentDate]]</b></code>, returns the current computer date in ''YYYMMdd'' format.
 +
* <code><b>[[ELDateToDateTime]]</b></code>, converts a date in ''YYmmdd'' format to a date into DateTime format.
 +
 
 +
See the [[:Category:Date_and_Time_Routines|Date & Time Routines]] for all EasyLanguage reserved words.
  
 
== Outputting the date ==
 
== Outputting the date ==
  
The following example prints the current date to the [[PowerLanguage Editor]] log:
+
The following example prints the current date to the [[Editor_Overview|PowerLanguage Editor]] log:
 
<syntaxhighlight>
 
<syntaxhighlight>
 
Print("The current date is: ", CurrentDate);
 
Print("The current date is: ", CurrentDate);
Line 11: Line 19:
 
Which returns the following sentence: ''The current date is: 1120127.00''.
 
Which returns the following sentence: ''The current date is: 1120127.00''.
  
To output the date in a more readable format, the reserved word [[FormatDate]] is needed. However, FormatDate requires that the date is in DateTime format, while the default Date is in YYYMMdd format. So, a conversion to DateTime is needed first. This is done with the [[ELDateToDateTime]] reserved word.  
+
To output the date in a more readable format, the reserved word <code><b>[[FormatDate]]</b></code> is needed. However, FormatDate requires that the date is in DateTime format, while the default Date is in YYYMMdd format. So, a conversion to DateTime is needed first. This is done with the <code><b>[[ELDateToDateTime]]</b></code> reserved word.
  
 
The code example below shows in detail which steps needs to be made.
 
The code example below shows in detail which steps needs to be made.
Line 51: Line 59:
 
== Outputting the date in different formats ==
 
== Outputting the date in different formats ==
  
The [[FormatDate]] reserved word has a parameter string by which different date outputs can be generated. For example, in the code above we used “dd-MM-yyyy” to return “27-1-2012”.
+
The <code><b>[[FormatDate]]</b></code> reserved word has a parameter string by which different date outputs can be generated. For example, in the code above we used "dd-MM-yyyy" to return "27-1-2012".
  
The code example below shows some of these parameter options for FormatDate (see the [[FormatDate]] article for an extensive list of parameter options).
+
The code example below shows some of these parameter options for FormatDate (see the <code><b>[[FormatDate]]</b></code> article for an extensive list of parameter options).
  
 
<syntaxhighlight>
 
<syntaxhighlight>

Latest revision as of 14:18, 23 February 2012

This article gives some tips and examples for outputting dates in EasyLanguage.

Relevant EasyLanguage Date reserved words

Just as a reminder, the following Date reserved words are often used in working with dates:

  • Date, which returns the Date of the current bar in YYYMMdd format. This date format is always the format with which a date calculation starts.
  • CurrentDate, returns the current computer date in YYYMMdd format.
  • ELDateToDateTime, converts a date in YYmmdd format to a date into DateTime format.

See the Date & Time Routines for all EasyLanguage reserved words.

Outputting the date

The following example prints the current date to the PowerLanguage Editor log:

Print("The current date is: ", CurrentDate);

Which returns the following sentence: The current date is: 1120127.00.

To output the date in a more readable format, the reserved word FormatDate is needed. However, FormatDate requires that the date is in DateTime format, while the default Date is in YYYMMdd format. So, a conversion to DateTime is needed first. This is done with the ELDateToDateTime reserved word.

The code example below shows in detail which steps needs to be made.

Variables:
	dateToday(0), dateInDateTimeFormat(0), dateReadable("");

// 1. Assign the date of today to the variable 'dateToday'
dateToday = CurrentDate;
Print("The current date in YYYMMdd format is: ", dateToday, NewLine);

// 2. Now, convert the date to DateTime format
dateInDateTimeFormat = ELDateToDateTime(dateToday);
Print("The current date in DateTime format is: ", NumToStr(dateInDateTimeFormat, 5), NewLine);

// 3. Now we can print the current date in a more readable format
dateReadable = FormatDate("dd-MM-yyyy", dateInDateTimeFormat);
Print("The current date in a readable format is: ", dateReadable);

This returns the following:

The current date in YYYMMdd format is: 1120127.00

The current date in DateTime format is: 40935.00000

The current date in a readable format is: 27-01-2012

Of course, not all these steps are needed. The extensive above example can be rewritten to simply:

Print("The current date in a readable format is: ", FormatDate("dd-MM-yyyy", ELDateToDateTime(CurrentDate)));

Which returns:

The current date in a readable format is: 27-01-2012

Outputting the date in different formats

The FormatDate reserved word has a parameter string by which different date outputs can be generated. For example, in the code above we used "dd-MM-yyyy" to return "27-1-2012".

The code example below shows some of these parameter options for FormatDate (see the FormatDate article for an extensive list of parameter options).

Variables:
	dateInDateTime(0);
	
dateInDateTime = ELDateToDateTime(CurrentDate);

Print("Date in short version: ", FormatDate("d-M-y", dateInDateTime), NewLine);

// Note: the output of the following statement depends on your regionale
Print("Date in abbreviations: ", FormatDate("ddd-MMM-yy", dateInDateTime), NewLine);

Print("Date fully written: ", FormatDate("dddd MMMM yyyy", dateInDateTime), NewLine);

Print("Date in a sentence: ", 
	FormatDate("The current Date is dddd anD the month is MMMM (which is month #MM). The Year is yyyy.", dateInDateTime));

end;

This gives the following output:

Date in short version: 27-1-12

Date in abbreviations: vr-jan-12

Date fully written: vrijdag januari 2012

Date in a sentence: The current Date is vrijdag anD the month is januari (which is month #01). The Year is 2012.