Date and Time to String, What do I miss???

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Date and Time to String, What do I miss???

Postby arjfca » 01 Sep 2011

Hello

I want to create a string to represent the ending date and time of a bar
Date string = YYYMMDD
Time string = HH:MM:SS.

To start i use:

Code: Select all

DatetoString(Date) return: 4941-07-16 // date = 2011-09-01
TimeToString (Time) return 00:00:00 // time = 09:45
Obviously it is not the proper way since the output of both DateToString And TimeToString are not related at all.

Any help appreciated

Martin

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Date and Time to String, What do I miss???

Postby JoshM » 01 Sep 2011

Straight from a custom function I wrote, so perhaps you need to change it somewhat:

Code: Select all

value50 = time_s[tmpBarsLookback] ; value51 = time_s[tmpExitBar];
tmpEntryTime = FormatTime("HH:mm:ss", el_timetodatetime_s(value50));
tmpEntryDate = FormatDate("d-M-yyyy", el_datetodatetime(EntryDate(1)));
tmpExitTime = FormatTime("HH:mm:ss", el_timetodatetime_s(value51));
tmpExitDate = FormatDate("d-M-yyyy", el_datetodatetime(ExitDate(1)));
Regards,
Josh

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Date and Time to String, What do I miss???

Postby TJ » 01 Sep 2011

Hello

I want to create a string to represent the ending date and time of a bar
Date string = YYYMMDD
Time string = HH:MM:SS.

To start i use:

Code: Select all

DatetoString(Date) return: 4941-07-16 // date = 2011-09-01
TimeToString (Time) return 00:00:00 // time = 09:45
Obviously it is not the proper way since the output of both DateToString And TimeToString are not related at all.

Any help appreciated

Martin
DatetoString requires a datetime input, not a "date" as in YYYYMMDD.
DateTime is a decimal valued unique serial number of a specific date/time.


Working with date/time in EasyLanguage is tricky.
EasyLanguage Reference Guide has the best explanation on EasyLanguage date/time operations.
https://www.TS.com/support/bo ... _Guide.pdf

CHAPTER: 2 - The Basic EasyLanguage Elements
Manipulating Dates and Times ...... pg 20

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Date and Time to String, What do I miss???

Postby TJ » 01 Sep 2011

this might give you an leg up in understanding date/time:
Programmer's Data Box
http://www.traderslaboratory.com/forums ... a-box.html

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Date and Time to String, What do I miss??? resolve

Postby arjfca » 01 Sep 2011

Hello

Here is my solution

Code: Select all

// Prepare the string of info to be sent to Excel.
// String are cut in shorter on to bypass somme limitation in MC
VAR:
TimeStr (""),
DateStr("");

//Time string output shoult be "HH:MM:SS"
TimeStr =text(Time); //Put the time in text
If StrLen(TimeStr)< 4 then timestr = "0" + timestr; // adjust for time lower than 10'
timestr = leftstr(timestr,2) + ":" + midstr(timestr,3,2) + ":00"; // Select appropriate value

//Date string output should be "YYYYMMDD"
Datestr = text(date + 19000000); // EL Date format start at 1900. Add this number and Text(it)
Datestr= leftstr(Datestr,8) ;
datestr = Datestr + " " + timestr;
Result:

Bar ending 2011 09 01 at 12:27= "20110901 12:27:00"

Martin


Return to “MultiCharts”