DateTime2ELDate

Questions about MultiCharts and user contributed studies.
bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

I went searching for something that might be named "DateTime2ELDate" which would match the DateTime2ELTime function. However I could not find such as function. So I ended up writing the set of commands below to convert the DateTime format into the standard 1YYMMDD format that EL code uses.

Code: Select all

MyDateTime = GetAppInfo(aiLeftDispDateTime);
strMyYear = formatdate("yy",MyDateTime);
strMyMonth = formatdate("MM",MyDateTime);
strMyDay = formatdate("dd",MyDateTime);
strMyDate = "1" + strMyYear + strMyMonth + strMyDay;
LeftSideOfScreenDate = strToNum(strMyDate);
Does anyone know if there an easier way (and preferably a faster way)? I was trying to avoid writing one of those century routines like the Julian routine since I needed it fast. Such code may run faster than what I wrote on the other hand.

If not, I guess I should create a function called A_DateTime2ELDate and put it in User Contributed.
Last edited by bowlesj3 on 21 Mar 2012, edited 1 time in total.

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

Re: DateTime2ELDate

Postby JoshM » 21 Mar 2012

Does anyone know if there an easier way (and preferably a faster way)? I was trying to avoid writing one of those century routines like the Julian routine since I needed it fast. Such code may run faster than what I wrote on the other hand.
If I understand you correctly, you can use DateToJulian to convert a DateTime numeric value to an ELDate value.

For example:

Code: Select all

Variables:
dtNow(ComputerDateTime);

if LastBarOnChart_s = true then begin

Print("Current date : ", FormatDate("dd-MM-yyyy", dtNow), " current time: ", FormatTime("HH:mm:ss", dtNow));

// Now, DateTime2ELDate
Print("DateTime: ", NumToStr(dtNow, 0), Spaces(5), "DateTime2ELDate: ", JulianToDate(dtNow));

end;
returns..

Code: Select all

Current date : 21-03-2012 current time: 16:24:27
DateTime: 40990 DateTime2ELDate: 1120321.00
.. where the DateTime2ELDate is the default EasyLanguage Date of YYYMMdd format with YYY being the number of years since 1900 (i.e. 1120321 for March 21st, 2012). :)

-----
Edit: In other words, your code of...

Code: Select all

MyDateTime = GetAppInfo(aiLeftDispDateTime);
strMyYear = formatdate("yy",MyDateTime);
strMyMonth = formatdate("MM",MyDateTime);
strMyDay = formatdate("dd",MyDateTime);
strMyDate = "1" + strMyYear + strMyMonth + strMyDay;
LeftSideOfScreenDate = strToNum(strMyDate);
..can be rewritten in my opinion (which might be wrong) to...

Code: Select all

LeftSideOfScreenDate = JulianToDate(GetAppInfo(aiLeftDispDateTime));
Last edited by JoshM on 21 Mar 2012, edited 1 time in total.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

Thanks Josh. I always knew Julian date to be the day number within the year so it never occurred to me to try the command that had Julian (thinking I would get the value of 1 for Jan first in any year). It sure looks easier and faster.

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

Re: DateTime2ELDate

Postby JoshM » 21 Mar 2012

(..)it never occurred to me to try the command that had Julian (thinking I would get the value of 1 for Jan first in any year).
I came across it by chance, so it was more luck than wisdom. ;)

MC Support, perhaps it might be a good idea to create a new reserved word 'DateTime2ELDate' that is the equivalent of JulianToDate, just as the reserved word 'EL_TimeToDateTime' is the equivalent of the 'ELTimeToDateTime' reserved word.

That might also make this date time conversion easier for beginners*, further lowering the learning curve of PowerLanguage.


*: I'm not talking about you John, but I assume if you and me already have to use workarounds/'tricks', beginners might not know how to even do it altogether.
Last edited by JoshM on 21 Mar 2012, edited 1 time in total.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

Totally agree. I had not checked to see if DateTime2ELTime was a function or reserve word. Now that I know I guess the DateTime2ELDate would be a good thing to put in project management as a feature request. It sounds like it may be one of the easiest request of all to put in since it would be a copy of julian code.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

Actually I just tried this and it bombed. I am trying to figure out why now.

Code: Select all

{
MyDateTime = GetAppInfo(aiLeftDispDateTime);
strMyYear = formatdate("yy",MyDateTime);
strMyMonth = formatdate("MM",MyDateTime);
strMyDay = formatdate("dd",MyDateTime);
strMyDate = "1" + strMyYear + strMyMonth + strMyDay;
LeftSideOfScreenDate = strToNum(strMyDate);
}
LeftSideOfScreenDate = DateToJulian(GetAppInfo(aiLeftDispDateTime));
No unfortunately

Code: Select all

LeftSideOfScreenDate = DateToJulian(GetAppInfo(aiLeftDispDateTime));
does not seem to work. It returns a number something like 1748.

Not a problem. Good try. The complex approach I came up with does work (for about 2 hours now at least). It will take a month to know for sure if it can handle anything.
Last edited by bowlesj3 on 21 Mar 2012, edited 1 time in total.

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

Re: DateTime2ELDate

Postby TJ » 21 Mar 2012

Actually I just tried this and it bombed. I am trying to figure out why now.
{
MyDateTime = GetAppInfo(aiLeftDispDateTime);
strMyYear = formatdate("yy",MyDateTime);
strMyMonth = formatdate("MM",MyDateTime);
strMyDay = formatdate("dd",MyDateTime);
strMyDate = "1" + strMyYear + strMyMonth + strMyDay;
LeftSideOfScreenDate = strToNum(strMyDate);
}
LeftSideOfScreenDate = DateToJulian(GetAppInfo(aiLeftDispDateTime));

No unfortunately
LeftSideOfScreenDate = DateToJulian(GetAppInfo(aiLeftDispDateTime));
does not seem to work. It returns a number something like 1748.
Not a problem. Good try.
YYYY portion of EL date is the number of years since 1900.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

I have never used the Julian command. Now I am curious and visiting the Wiki on it.

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

Re: DateTime2ELDate

Postby TJ » 21 Mar 2012

the formula should be

Code: Select all

left.date = juliantodate( getappinfo( aileftdispdatetime ) );

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

Wiki heaven. Hah, it should then be JulianToDate (the reverse of DataToJulian). Lets try that.

Now that worked. The solution is

Code: Select all

{
MyDateTime = GetAppInfo(aiLeftDispDateTime);
strMyYear = formatdate("yy",MyDateTime);
strMyMonth = formatdate("MM",MyDateTime);
strMyDay = formatdate("dd",MyDateTime);
strMyDate = "1" + strMyYear + strMyMonth + strMyDay;
LeftSideOfScreenDate = strToNum(strMyDate);
}
LeftSideOfScreenDate = JulianToDate(GetAppInfo(aiLeftDispDateTime));

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

Thanks TJ. I guess I figured out to flip the command as you were creating your post.

I am thinking JulianToDate should be actuallly called CenturyToDate but maybe my understanding of the meaning Julian is incorrect. Julian reminds me of a school project over 30 years ago. We had a Julian project and a century project for dates. During the century project I remember learning that leap years are even 4 division except if divided by 100 except if divided by 400. Funny how some things stick in memory.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 21 Mar 2012

I was correct. Julian data is the number of days within the year and century date is the number of days from the start of the century (1900 - the century that computers were invented). If interested see the links below where I checked to see if I remembered it correctly. That is why I didn't bother looking at the Julian commands. (not to mention that I have never really needed the calc before today).

Julian Date Definition
http://www.cpearson.com/excel/jdates.htm
Normally YY### format where number is a number from 1 to 366.

Century Date Definition
http://www.answers.com/topic/century-date

In theory the commands should be
CenturyDate2ELdate or ELdate2CenturyDate
JulianDate2ELDate or ELdate2JulianDate

However having a Century Date command basically eliminates the need for Julian date.

Not a big deal but interesting anyway.

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

Re: DateTime2ELDate

Postby TJ » 21 Mar 2012

I was correct. Julian data is the number of days within the year and century date is the number of days from the start of the century (1900 - the century that computers were invented). If interested see the links below where I checked to see if I remembered it correctly. That is why I didn't bother looking at the Julian commands. (not to mention that I have never really needed the calc before today).

Julian Date Definition
http://www.cpearson.com/excel/jdates.htm
Normally YY### format where number is a number from 1 to 366.

Century Date Definition
http://www.answers.com/topic/century-date

In theory the commands should be
CenturyDate2ELdate or ELdate2CenturyDate
JulianDate2ELDate or ELdate2JulianDate

However having a Century Date command basically eliminates the need for Julian date.

Not a big deal but interesting anyway.
EasyLanguage was invented in 1900's.

A code written in the 1900's might not run correctly today with CenturyDate2ELdate.


just a thought. ;-)

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: DateTime2ELDate

Postby bowlesj3 » 22 Mar 2012

Actually the terms should be (to be highly technically correct I suppose)

CenturyDateTime2ELdate and CenturyDateTime2ELtime
inverted
ELdate2CenturyDateTime and ELtime2CenturyDateTime

The fact that it crosses two centuries would not impact the use of Century in the name (correcting the miss use of Julian).

Sort of related to your comments, Yes I am not sure why Julian YY### format would still be used when these types of century calculations are available now.

I think if these names were used I would have understood this whole area almost immediately since I did those school projects many years ago. Maybe I will write a wrapper function to call these julian reserve words so I start using the correct names. It might be handy when I get into my 90s . . . when and the mind slows down even more and am making billions on every trade :-)


Return to “MultiCharts”