You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/07/11 05:06:23 UTC

[GitHub] [superset] zhaoyongjie edited a comment on issue #15613: How do I get current datetime in the SQLTemplate?

zhaoyongjie edited a comment on issue #15613:
URL: https://github.com/apache/superset/issues/15613#issuecomment-877742092


   we can make macros in the `config.py`, for instance:
   
   ```
   from datetime import datetime
   
   def current_datetime():
       return datetime.now().strftime("%Y-%m-%d")
   
   JINJA_CONTEXT_ADDONS = {
       "current_datetime": current_datetime
   }
   ```
   
   ensure that the flag `ENABLE_TEMPLATE_PROCESSING` is enabled
   ```
   FEATURE_FLAGS = {
       ...
       "ENABLE_TEMPLATE_PROCESSING": True,
   }
   ```
   
   Then use in SQLLab
   
   ```
   select ...
   from ...
   where start > {{ current_datetime() }}
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org