guitarguy1685 发表于 2022-7-5 20:26:09

Date format (i.e. 23DEC14)

So I know how to get the date from autocad using CDATE.And I know how to parse that info to get 12/23/14.But how can I, for example, get the 12 to be "DEC".Do I need to make a multiple if statement for that part of the string?

hanhphuc 发表于 2022-7-5 20:30:17

 
you can use..
(cond (1 "JAN")(2 "FEB")....)
 
my example using mapcar

(defun mth ( m / i l);hanhphuc 24/12/2014(setq i 13 )(eval(cons 'cond (mapcar '(lambda (a b /) (list (eval (cons '= (list m 'a))) b))       (repeat 12 (setq l (cons (setq i (1- i)) l)))       '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEPT" "OCT" "NOV" "DEC")       ) ;_ end of mapcar ) ;_ end of cons) ;_ end of eval)
functional call:
 
(mth 12) ; returns "DEC"
 
since you know coding, so the rest try it yourself using string function
strcat , substr , vl-string-search
etc..
 
p/s: i'm ibanez fanmerry X'mas donate to CADtutor

ymg3 发表于 2022-7-5 20:34:34

guitarguy1685,
 
Alternatively, simply create an assoc list like so:
 

(setq month '((1 . "JAN")(2 . "FEB")(3 . "MAR")(4 . "APR")      (5 . "MAY")(6 . "JUN")(7 . "JUL")(8 . "AUG")      (9 . "SEP")(10 . "OCT")(11 . "NOV")(12 . "DEC")))
 
Now whenever you need the month just issue:
 
(cdr (assoc 3 month)) will return "MAR" etc.
 
ymg

hanhphuc 发表于 2022-7-5 20:39:37

1+
 
season greetings:
ymg, i'd like to take this opportunity to credit some of your sub-functions i used in this forum.
thank you
 
merry X'mas
hanhphuc

ymg3 发表于 2022-7-5 20:45:23

hanhphuc,
 
Season's greeting ! to you too
and all the best.
 
ymg

Tharwat 发表于 2022-7-5 20:48:30

Another ,
 

(nth (1- 12) '("JAN" "FEB" "MAR" "APR" "MAY" "JUN" "JUL" "AUG" "SEP" "OCT" "NOV" "DEC"))

AIberto 发表于 2022-7-5 20:53:35

;;date-->cdate
;;;;http://bbs.mjtd.com/thread-112484-1-1.html

(defun Date->CDate (date / s) (setq s (strcat "M=$(edtime," (rtos date 2",YYYYMODD.HHMMSS)")) (atof (menucmd s))) ;defun
 
;;cdate-->date
;;;;http://bbs.mjtd.com/thread-112484-1-1.html

(defun CDate->Date (cdate / Round Time Diff cd dt i0 i n s) (defun Round (x)   (if      (>= x 0)   (fix (+ x 0.5))   (fix (- x 0.5))   ) ;if ) ;defun (defun Time (dt / x h m s)   (setq x (Round (rem (* dt 1E6) 1E6)))   (setq h (/ x 10000)         m (/ (rem x 10000) 100)         s (rem x 100)   )   (/ (+ (* 3600 h) (* 60 m) s) 8.64E4) ) ;defun(defun Diff (cd1 cd2 / y1 y2 m1 m2 d1 d2 n)   (cond   ((= cd1 cd2) (setq n 0))   ((setq y1      (/ cd1 10000)            m1      (rem (/ cd1 100) 100)            d1      (rem cd1 100)            y2      (/ cd2 10000)            m2      (rem (/ cd2 100) 100)            d2      (rem cd2 100)            n      (Round (+ (* 366 (- y1 y2)) (* 30.5 (- m1 m2)) (- d1 d2)))      )      (and (= n 0) (setq n nil))   )   ) ;cond   n ) ;defun(setq      cd (fix cdate)       dt -47130101       i0 0       n0 ) (while (and (setq i (Diff cd dt)) (/= i 0) (/= 0 (+ i i0)))   (setq n(+ n i)         s(strcat "M=$(edtime," (itoa n) ",YYYYMODD)")         dt (atoi (menucmd s))         i0 i   ) ) ;while (if (or (not i) (= 0 (+ i i0)))   (setq n nil) ) ;if (and n (setq n (+ n (Time cdate)))) n) ;defun

hanhphuc 发表于 2022-7-5 20:54:56

 
Thanks Tharwat.
simple & clean
 
This similar but it index nth in a string

(menucmd (strcat "M=$(index, "       (itoa (1- i)) ; i= integer       " ,\"JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEPT,OCT,NOV,DEC\")"       ) )

Tharwat 发表于 2022-7-5 21:01:27

 
You are welcome anytime

pBe 发表于 2022-7-5 21:03:54

 
That would be (1- n)
 
Be mindful of the index number, or(0-11)
 
nth 0 is the first element, it might confused the OP.
页: [1] 2
查看完整版本: Date format (i.e. 23DEC14)