Page 1 of 1

dateformat - - expected results?

Posted: 14 Dec 2019 06:18
by DaveyJones
Works
"{selectedDateTime,dateformat,yyyy-MM-dd_HH:mm}" ;

Fails
"{selectedDateTime,dateformat,yyyy-MM-ddTHH:mm}" ;

2019-05-10T13:45 is a sort of standardized format... But the T throws it off...

Expected?

Re: dateformat - - expected results?

Posted: 14 Dec 2019 08:41
by Desmanto
Working as expected. T is not the date pattern available. To show a simple char/string inside the format, you have to single quote, 'T'
So the correct one should be.

Code: Select all

select = "{selectedDateTime,dateformat,yyyy-MM-dd'T'HH:mm}" ;

Re: dateformat - - expected results?

Posted: 14 Dec 2019 18:02
by jassing
I ran into a similar problem, so I wanted to use a variable to hold the format... Made things worse, since I couldn't do

Code: Select all

{selectedDateTime,dateformat,datefmt}

Re: dateformat - - expected results?

Posted: 14 Dec 2019 19:17
by Desmanto
@jassing : You can't put variable inside the dateformat pattern directly. Use eval() and concat the string inside.

Code: Select all

datefmt = "yyyy-MM-dd'T'_HH:mm";
t = eval('"{triggertime,dateformat,' + datefmt + '}"');
You can even decoupled out the time variable part.

Code: Select all

datefmt = "yyyy-MM-dd'T'_HH:mm";
t = eval('"{' + triggertime + ',dateformat,' + datefmt + '}"');
Or even decoupled the format part, but I don't think you have to do that unless you are really get into creating your own custom function.

Re: dateformat - - expected results?

Posted: 15 Dec 2019 03:13
by jassing
Neat, I know it won't work... Now. but that would work not in script? For instance writing to a file?

Re: dateformat - - expected results?

Posted: 15 Dec 2019 10:06
by Desmanto
You mean eval() + concat method? As long as the final result is what you want, then writing to a file should be correct too. I used to use one of these variable dateformatting before, and then I just make the formatting fixed instead. Better use more script lines than to confuse my future self.

It is just much harder to use eval when you combine too many variable inside. Because you have to take care of the single and double quote, the line separation (if needed) and especially when dealing with regex which can contain so many symbol character.