date functions added

This commit is contained in:
2021-05-20 23:03:03 +02:00
parent 75a6e186a6
commit 5dd336d382
3 changed files with 33 additions and 0 deletions

View File

@@ -135,6 +135,16 @@
(quick-sort-by l (lambda (a b) (> a b))))
(defun start-of-day (datetime) (str-to-date (+ (date-to-str datetime "%Y-%m-%d") " " "00:00:00") "%Y-%m-%d %H:%M:%S"))
(defun end-of-day (datetime) (str-to-date (+ (date-to-str datetime "%Y-%m-%d") " " "23:59:59") "%Y-%m-%d %H:%M:%S"))
(defun start-of-month (datetime) (str-to-date (+ (date-to-str datetime "%Y-%m") "-01 00:00:00") "%Y-%m-%d %H:%M:%S"))
(defun start-of-next-month (datetime) (date-add (start-of-month datetime) 1 "month"))
(defun end-of-next-month (datetime) (date-add (end-of-month datetime) 1 "month"))
(defun end-of-month (datetime) (date-add (date-add (start-of-month datetime) 1 "month") -1 "second"))
(defun start-of-prev-month (datetime) (date-add (start-of-month datetime) -1 "month"))
(defun end-of-prev-month (datetime) (date-add (end-of-month datetime) -1 "month"))
(defun start-of-year (datetime) (str-to-date (+ (date-to-str datetime "%Y") "-01-01 00:00:00") "%Y-%m-%d %H:%M:%S"))
(defun end-of-year (datetime) (str-to-date (+ (date-to-str datetime "%Y") "-12-31 23:59:59") "%Y-%m-%d %H:%M:%S"))
; from list of lists creates csv string