Store formated date into variable
Moderator: Martin
Store formated date into variable
Hi, I want to convert a date into a readable format using "getDate(),dateformat,dd.MM.yyyy HH:mm:ss" and store this string into a new variable.
This does not work directly at the moment. Correct me if I am wrong.
Currently I a have a work arround storing the date in the readable format into a text file and read it back into a variable. It works but it would be great if there will be the possibility to do it directly.
Thanks.
This does not work directly at the moment. Correct me if I am wrong.
Currently I a have a work arround storing the date in the readable format into a text file and read it back into a variable. It works but it would be great if there will be the possibility to do it directly.
Thanks.
Re: Store formated date into variable
Set it up as a global variable.
Re: Store formated date into variable
Hi, I want to do it that way:
Script: global_test={getDate(),dateformat,dd.MM.yyyy HH:mm:ss};
but it does not work.
global_test is declared as a string.
Script: global_test={getDate(),dateformat,dd.MM.yyyy HH:mm:ss};
but it does not work.
global_test is declared as a string.
Re: Store formated date into variable
Try this:
Change the declaration to "Date" ... I've tried it ... it works well.
Does it also work at your side?
Change the declaration to "Date" ... I've tried it ... it works well.
Does it also work at your side?
Re: Store formated date into variable
Unfortunately not. I changed the data type to date but it still not work. There are red colored errors shown in the action 'script'. And if I run the flow it stops there due to an error.
I also tried this:
Script: eval("global_test=getDate(),dateformat,dd.MM.yyyy HH:mm:ss");
But it does not work.
I also tried this:
Script: eval("global_test=getDate(),dateformat,dd.MM.yyyy HH:mm:ss");
But it does not work.
-
- Posts: 56
- Joined: 16 Mar 2013 14:10
Re: Store formated date into variable
I have been trying to follow this with little luck. I think when you format the date it becomes a string. Without the formatting it looks like a long integer.
Please upload the flow so l can look at it and the error.
Please upload the flow so l can look at it and the error.
Re: Store formated date into variable
Please try the following (note the doublequotes):
global_test="{getDate(),dateformat,dd.MM.yyyy HH:mm:ss}"
global_test="{getDate(),dateformat,dd.MM.yyyy HH:mm:ss}"
Re: Store formated date into variable
Hi Martin,
thank you. It works now.
thank you. It works now.
Re: Store formated date into variable
Hi,
i have tried this, and it works:
datum="{getDate(),dateformat,dd.MM.yyyy HH:mm:ss}"
But what i need is a function that calculate a given UTC time into it's MESZ time.
The given UTC time is in a human readable format, like: 20130425-192000 (25.April 2013 - 19:20:00 o'clock)
I think, it is possible to add 2 hours to utc with
UTC_date=getDate(2013,04,25,19,20,00) // UTC_date is now "1366910400000"
MESZ_date=addHours({UTC_date}, 2) // MESZ_date is now "1366917600000"
Now i want to turn the java date into a human readable format, like this: 20130425-212000 - But no one of my codes worked:
Human_MESZ=getDate({MESZ_date},dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ=getDate("{MESZ_date}",dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ=getDate(MESZ_date,dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ="getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)" // Human_MESZ is then "getDate(1366917600000,dd.MM.yyyy HH:mm:ss)"
Human_MESZ={getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)} // Could not execute...
Human_MESZ="{getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)}" // Human_MESZ is "{error}"
Human_MESZ={getDate({MESZ_date}),dateformat,dd.MM.yyyy HH:mm:ss} // Could not execute...
Human_MESZ="{getDate({MESZ_date}),dateformat,dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Human_MESZ="{getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ="{getDate(MESZ_date),dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ="{getDate(),{MESZ_date},dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ={getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss} // Could not execute...
Human_MESZ="{getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Even when i put the java date directly into the code, i'll get only errors:
Human_MESZ=getDate(1366917600000,dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ="{getDate(1366917600000),dateformat,dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Human_MESZ="{getDate("1366917600000"),dateformat,dd.MM.yyyy HH:mm:ss}" // Could not execute...
Where is my problem??
i have tried this, and it works:
datum="{getDate(),dateformat,dd.MM.yyyy HH:mm:ss}"
But what i need is a function that calculate a given UTC time into it's MESZ time.
The given UTC time is in a human readable format, like: 20130425-192000 (25.April 2013 - 19:20:00 o'clock)
I think, it is possible to add 2 hours to utc with
UTC_date=getDate(2013,04,25,19,20,00) // UTC_date is now "1366910400000"
MESZ_date=addHours({UTC_date}, 2) // MESZ_date is now "1366917600000"
Now i want to turn the java date into a human readable format, like this: 20130425-212000 - But no one of my codes worked:
Human_MESZ=getDate({MESZ_date},dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ=getDate("{MESZ_date}",dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ=getDate(MESZ_date,dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ="getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)" // Human_MESZ is then "getDate(1366917600000,dd.MM.yyyy HH:mm:ss)"
Human_MESZ={getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)} // Could not execute...
Human_MESZ="{getDate({MESZ_date},dd.MM.yyyy HH:mm:ss)}" // Human_MESZ is "{error}"
Human_MESZ={getDate({MESZ_date}),dateformat,dd.MM.yyyy HH:mm:ss} // Could not execute...
Human_MESZ="{getDate({MESZ_date}),dateformat,dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Human_MESZ="{getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ="{getDate(MESZ_date),dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ="{getDate(),{MESZ_date},dd.MM.yyyy HH:mm:ss}" // Could not execute...
Human_MESZ={getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss} // Could not execute...
Human_MESZ="{getDate({MESZ_date}),dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Even when i put the java date directly into the code, i'll get only errors:
Human_MESZ=getDate(1366917600000,dd.MM.yyyy HH:mm:ss) // Could not execute...
Human_MESZ="{getDate(1366917600000),dateformat,dd.MM.yyyy HH:mm:ss}" // Human_MESZ is "{error}"
Human_MESZ="{getDate("1366917600000"),dateformat,dd.MM.yyyy HH:mm:ss}" // Could not execute...
Where is my problem??
Re: Store formated date into variable
Hi,
Automagic uses the milliseconds since 1970 for all dates (it does not wrap this value in a Date object like it is often done in Java). When you have a variable with the millis, then you are already done and can directly use the variable in a string inline expression to format the number.
Following should work in a scripting context (in an action Script, condition Expression etc.):
UTC_date=getDate(2013,04,25,19,20,00);
MESZ_date=addHours(UTC_date, 2);//no need for curly braces around UTC_date
Human_MESZ="{MESZ_date,dateformat,dd.MM.yyyy HH:mm:ss}";
Inline formatting syntax
{expression,formattype,pattern}
expression can be either a variable like MESZ_date, a function call like getDate(), a plain value like 1366910400000 or a small script.
formattype must be dateformat in this case
pattern the date-pattern to use to format the date (like dd.MM.yyyy HH:mm:ss)
Examples (in a script context):
x="{MESZ_date,dateformat,HH:mm}";
x="{1366910400000,dateformat,HH:mm}";
x="{getDate(),dateformat,HH:mm}";
x="{addHours(getDate(),2),dateformat,HH:mm}";
or since a date is just a number (millis since 1970):
x="{getDate()+2*60*60*1000,dateformat,HH:mm}";
The syntax is almost the same in regular text fields of many actions.
Examples (in a non-script context like the text field of an action Notification on Screen):
{MESZ_date,dateformat,HH:mm}
{1366910400000,dateformat,HH:mm}
{getDate(),dateformat,HH:mm}
{addHours(getDate(),2),dateformat,HH:mm}
Regards,
Martin
Automagic uses the milliseconds since 1970 for all dates (it does not wrap this value in a Date object like it is often done in Java). When you have a variable with the millis, then you are already done and can directly use the variable in a string inline expression to format the number.
Following should work in a scripting context (in an action Script, condition Expression etc.):
UTC_date=getDate(2013,04,25,19,20,00);
MESZ_date=addHours(UTC_date, 2);//no need for curly braces around UTC_date
Human_MESZ="{MESZ_date,dateformat,dd.MM.yyyy HH:mm:ss}";
Inline formatting syntax
{expression,formattype,pattern}
expression can be either a variable like MESZ_date, a function call like getDate(), a plain value like 1366910400000 or a small script.
formattype must be dateformat in this case
pattern the date-pattern to use to format the date (like dd.MM.yyyy HH:mm:ss)
Examples (in a script context):
x="{MESZ_date,dateformat,HH:mm}";
x="{1366910400000,dateformat,HH:mm}";
x="{getDate(),dateformat,HH:mm}";
x="{addHours(getDate(),2),dateformat,HH:mm}";
or since a date is just a number (millis since 1970):
x="{getDate()+2*60*60*1000,dateformat,HH:mm}";
The syntax is almost the same in regular text fields of many actions.
Examples (in a non-script context like the text field of an action Notification on Screen):
{MESZ_date,dateformat,HH:mm}
{1366910400000,dateformat,HH:mm}
{getDate(),dateformat,HH:mm}
{addHours(getDate(),2),dateformat,HH:mm}
Regards,
Martin