How to get current date and time in YYYYMMDDHHMMSS format ?
I would like to get current date and time in this format : YYYYMMDDHHMMSS (eg: 20220126155704)
Simplest way to do that I found so far is this :
$translate($zdatetime($horolog,8,1), " :", "")
It works, but it's not that great (I would like to avoid string manipulation) Is there a better, cleaner way ?
Product version: Caché 2018.1
Hello,
Please try below, this should help you !
Output : 20220127113314
Output : 20220127113314
You can use either of the above two , both works !
Thanks,
Anusri
Use TO_CHAR:
In Caché 2018.1, which the author indicated, there is no such function.
In addition, instead of HH need to specify HH24, otherwise instead of 20220126155704 will get 20220126035704.
Delimiters in the format are required, so you will have to manipulate the strings anyway.
Assumes you have Ensemble/Interoperability, though ...
Your solution is just perfect. And fast.
But yes, you can avoid string manipulations... This one, for example, uses math only, merely it's neither short nor looks elegant:
but gives the same result as your short and nice solution...
On the other hand, you can install new brakes on your car, as suggested by others... ;-))
Just compare those codes with yours:
The choice is yours...
factor 64.7 times faster
Here is a test for running all those codes.
It looks like that the 1st solution (with $translate) is the fastest.
You forgot to take into account the $system.SQL.* variants . They make much more fun, especially because you get time for a coffee break...
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue