Help with manipulating CDATE

Help with manipulating CDATE

schmidtjBEEVY
Advocate Advocate
423 Views
7 Replies
Message 1 of 8

Help with manipulating CDATE

schmidtjBEEVY
Advocate
Advocate

Hello all,

 

I want to write a routine to put the following year onto my drawing index page. I found this function in some old code written before I started, and I didn't know if there was way to reverse the rtos. 

 

(defun :GETDATE (/ x)
		(setq x (getvar "CDATE"))  ;; CURRENT DATE
		(setq x (rtos x 2 6))      ;; CONVERT TO STRING
		(setq date (strcat (substr x 5 2) "/" 	;; MM
				   (substr x 7 2) "/"   ;; DD
				   (substr x 3 2) " ")  ;; YY
		 )
	)

 

My thought process is I can use the rtos to isolate the year from CDATE in a YYYY format, then convert it back into an INT/REAL and increment it to print it onto a tag on my drawing index. But I don't know how to go about converting it back into an INT/REAL, if that's at all possible. If anyone has any suggestions, please let me know.

 

Thank you!

-JD

 

0 Likes
Accepted solutions (1)
424 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Perhaps this is all you need

 

(fix (/ (getvar 'cdate) 1e4))

 

The conversion func you're looking for is the ATOI or ATOF.

Message 3 of 8

schmidtjBEEVY
Advocate
Advocate

Hi BeekeeCZ

 

I accidentally hit accept solution instead of reply (I might need new glasses haha).

 

Thanks for the suggestion. I looked at the FIX instruction information on m reference doc's and it doesn't quite make sense to me how it will work with CDATE. How is CDATE supposed return when using GETVAR? When I looked into it earlier it seemed to be returning in the format Y.YYYMMDD<time> .

 

Thanks again,

JD

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Well, does the posted code return something else than the year?

 

Not sure what your reference book says but mine tells me that it returns:  

20060209.15050000

So divide it by 10000, fix it... no magic's in there.

Message 5 of 8

schmidtjBEEVY
Advocate
Advocate

It does, but I put a (princ x) before the line with the rtos on it to try and get around that.

I will take another look at it, and implement the fix instruction.

 

Thanks again, BeekeeCZ!

-JD

 

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

Another approach:

 

(atoi (substr (rtos (getvar 'cdate) 2) 1 4))

Kent Cooper, AIA
Message 7 of 8

schmidtjBEEVY
Advocate
Advocate

Thanks for the other approach.

 

BeekeeCZ's method has been doing the trick so far, but I'll keep this one in mind.

 

Best regards,

-JD

0 Likes
Message 8 of 8

ronjonp
Mentor
Mentor

Use menucmd:

(menucmd "M=$(edtime, $(getvar,date),YYYY/MO/DD HH:MM:SS)")
;; "2022/09/15 09:43:11"
(menucmd "M=$(edtime, $(getvar,date),YYYY/MO/DD)")
;; "2022/09/15"
(atoi (menucmd "M=$(edtime, $(getvar,date),YYYY)"))
;; 2022