Jump to content

Date format (i.e. 23DEC14)


Recommended Posts

Posted

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?

Posted
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?

 

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 fan :) merry X'mas donate to CADtutor

Posted

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

Posted

Now whenever you need the month just issue:

 

(cdr (assoc 3 month)) will return "MAR" etc.

 

ymg

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

Posted (edited)

hanhphuc,

 

Season's greeting ! to you too

and all the best.

 

ymg

Edited by ymg3
Posted

Another ,

 

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

Posted

;;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
       n  0
 )
 (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

Posted (edited)
Another ,

 

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

 

Thanks Tharwat.

simple & clean :thumbsup:

 

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\")"
	 ) )

Edited by hanhphuc
Posted
Another ,

 

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

 

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.

Posted
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.

 

pBe

 

actually Tharwat applied decrease , (1- n)

ie: (1- 12) =11 th

but it also looks like (1 - 12), OP maybe confused if not coloured tag :)

Posted
pBe

 

actually Tharwat applied decrease , (1- n)

ie: (1- 12) =11 th

but it also looks like (1 - 12), OP maybe confused if not coloured tag :)

 

Oh i see, its must be my eyes..

 

Thank you for clarifying hanhphuc. :) kudos to Tharwat

 

Personally i prefer an association list to avoid confusion such as the one above.

Posted

Thank you hanhphuc for the clarifications , appreciated alot :)

 

Thank you for clarifying hanhphuc. :) kudos to Tharwat

 

Thank you pBe :)

Posted
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?

Hi guitarguy1685,

a different approach, not using 'CDATE' but also getting the date format as your exemple '23DEC13'

(menucmd "m=$(edtime,0,ddmonyy)")
;; returns "28Dec14"
;; if uppercase is required
(strcase(menucmd "m=$(edtime,0,ddmonyy)"))
;; returns "28DEC14"

I hope this helps

Henrique

Posted

(strcase(menucmd "m=$(edtime,0,ddmonyy)"))
;; returns "28DEC14"

 

This is the method I would have suggested :)

 

Nice one Henrique :thumbsup:

Posted
This is the method I would have suggested :)

 

Nice one Henrique :thumbsup:

 

 

Thank you, Lee :)

 

Cheers

Henrique

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...