CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 6907

CAD tip CAD tip # 14063:

   
Question CAD 
 %  platform  category 
Q - question

How to get week day and week number from a given date.

A - answer The AutoCAD DIESEL function edtime can get most date-formatting information from a given date value - see e.g.:

(menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D. MONTH YYYY)")

But you cannot get the day of the week (Mon,Tue...) as a number code and you cannot get the weeknumber as per the ISO 8601 through this mechanism.

For these cases you can use the following LISP code developed by Lee Mac:

;; Week Number - Lee Mac ;; Returns the ISO 8601 week number for a given date (defun LM:weeknumber ( y m d ) ( (lambda ( q ) (cond ( (< q 1) (LM:weeknumber (1- y) 12 28)) ( (and (< 28 d) (< 51 q) (< (LM:weeknumber y 12 28) q)) 1) ( q ) ) ) (/ (+ (nth m '(0 0 31 59 90 120 151 181 212 243 273 304 334)) (if (and (LM:leapyear-p y) (< 2 m)) 1 0) (- (LM:weekday y m d)) 9 d ) 7 ) ) ) ;; Weekday - Lee Mac ;; Returns an integer 0-6 (0=Monday;6=Sunday) corresponding to the day of ;; the week for a given date ;; Implementation of Zeller's Congruence Algorithm (defun LM:weekday ( y m d ) (if (< m 3) (setq y (1- y) m (+ m 12))) (rem (+ 5 d (/ (* 26 (1+ m)) 10) y (/ y 4) (* 6 (/ y 100)) (/ y 400)) 7) ) ;; LeapYear-p - Lee Mac ;; Returns T if the supplied year number is a leap year (defun LM:leapyear-p ( y ) (and (zerop (rem y 4)) (or (zerop (rem y 400)) (not (zerop (rem y 100))) ) ) ) ;; Added by CADforum: get TODAY's values: (setq __today (read (menucmd "M=$(edtime,$(getvar,date),\"(\"YYYY M D\")\")"))) (LM:weekday (car __today)(cadr __today)(caddr __today))
ACADACLTADTACADMPlantMapCivil3D
100% *  CAD 
13.3.2024    31738×  

See also:
Tip 13868:XrefStamp - create a dynamic list of xrefs in your DWG drawing.
Tip 13513:How to quickly record a video from a CAD application or other Windows program? (replacing Screencast)
Tip 13459:DWG drawing version history directly in AutoCAD.
Tip 11914:Maze generator for AutoCAD.
Tip 11303:"Clock Error" when starting Autodesk CAD application.


Back   All CAD Tips



Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
Export 3D VRML scenes from AutoCAD and Inventor
VRMLout More info


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist