Author Topic: Vlisp e date  (Read 3987 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Vlisp e date
« on: April 26, 2012, 12:12:24 PM »
Hello everyone,
exists in lisp or vlisp some functions to work with dates?

I have to perform subtraction, and sums between dates.

deegeecees

  • Guest
Re: Vlisp e date
« Reply #1 on: April 26, 2012, 12:24:25 PM »
Here's a quick one:

Code: [Select]
(defun dater ()
(setq d (rtos (getvar "CDATE") 2 6)
yr (substr d 3 2)
mo (substr d 5 2)
day (substr d 7 2)
)

     (setq the_date (strcat mo "-" day "-" yr))
)

Lupo76

  • Bull Frog
  • Posts: 343
Re: Vlisp e date
« Reply #2 on: April 26, 2012, 12:36:06 PM »
Thanks for the reply.
I understand that in Lisp, there are no dedicated functions for manipulating dates.
In VBA, the dates are considered as the number of days from I think from 01.01.1970, and then simply use the "+" and "-".

how can I convert the number 15456 to a date (04.26.2012) in vlisp?

is it possible?

BlackBox

  • King Gator
  • Posts: 3770
Re: Vlisp e date
« Reply #3 on: April 26, 2012, 12:52:39 PM »
FWIW -

Code - Auto/Visual Lisp: [Select]
  1. (defun _Date ()
  2.   (menucmd "M=$(edtime,$(getvar,date),YYYY-MO-DD)"))
  3.  
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Vlisp e date
« Reply #4 on: April 26, 2012, 12:57:18 PM »
For reference....

Help > Customization Guide > DIESEL > Catalog of DIESEL Functions > edtime

You can customize the output you want, see the 'Format Phrases' section at the above link.

HTH
"How we think determines what we do, and what we do determines what we get."

deegeecees

  • Guest
Re: Vlisp e date
« Reply #5 on: April 26, 2012, 01:08:24 PM »
^^^or from the Help file:

Quote
DATE System Variable
(Read-only)
Type: Real
Not saved

Stores the current date and time. This value is represented as a Modified Julian Date (MJD), which is the Julian day number and decimal fraction of a day in the format :

<Julian day number>.<Decimal fraction of a day>

The Modified Julian Date, conventionally called UT1, is a worldwide scientific standard that assigns day numbers beginning at an essentially arbitrary date and time of 12:00 a.m. on 1 January 4713 B.C. (B.C.E.). With this system, 4 July 1997 at 2:29:58 p.m. corresponds to 2450634.60387736, and 1 January 1998 at 12:00 noon corresponds to 2450815.50000000.


You can compute differences in date and time by subtracting the numbers returned by DATE. To extract the seconds since midnight from the value returned by DATE, use AutoLISP expressions:


(setq s (getvar "DATE"))

(setq seconds (* 86400.0 (- s (fix s))))


Because your computer clock provides the date and time, the DATE system variable returns a true Julian date only if the system clock is set to UTC/Zulu (Greenwich Mean Time). TDCREATE and TDUPDATE have the same format as DATE, but their values represent the creation time and last update time of the current drawing.

BlackBox

  • King Gator
  • Posts: 3770
Re: Vlisp e date
« Reply #6 on: April 26, 2012, 01:10:48 PM »
I'll stick with the edtime alternative for simplicity... Specify the desired output format and done. Lemon squeezy.  :kewl:
"How we think determines what we do, and what we do determines what we get."

deegeecees

  • Guest
Re: Vlisp e date
« Reply #7 on: April 26, 2012, 01:21:12 PM »
I can def. see the logic in that. He asked for Lisp, so...

BlackBox

  • King Gator
  • Posts: 3770
Re: Vlisp e date
« Reply #8 on: April 26, 2012, 01:34:54 PM »
I can def. see the logic in that. He asked for Lisp, so...

Plankton, I'd like to introduce you to my friend Menucmd... Don't mind him, he's from the AutoLISP Reference Guide.


 :-P

... Sorry, just been one of those days.  :lol:
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Vlisp e date
« Reply #9 on: April 26, 2012, 03:12:18 PM »

Lupo76

  • Bull Frog
  • Posts: 343
Re: Vlisp e date
« Reply #10 on: April 30, 2012, 04:45:26 AM »
Hello everyone,
I thank you for the answers.
Sorry if I answer only now, m I had major problems connecting to the internet  :-(

Unfortunately, maybe I was not clear enough.
I read from an external txt file out dates expressed in number of seconds since 01.01.1970, so I have some numbers that may be 1000 or 1656, or 56541, etc..

Now I need to convert these numbers into a date expressed in any way (eg 14/05/2012 or "5/14/2012 | 12:55" etc..)

The solution (menucmd "M = $ (edtime, $ (getvar, date), MO-DD-YYYY)") suggested by RenderMan is fine, but I could not figure out you can replace s (getvar, date) with a number : I tried but it does not work.

I navigated through the other links that you have mentioned but none of these gave the solution to my problem.  :cry:
Do you have any idea?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Vlisp e date
« Reply #11 on: April 30, 2012, 06:35:20 AM »
I read from an external txt file out dates expressed in number of seconds since 01.01.1970, so I have some numbers that may be 1000 or 1656, or 56541, etc..

You are describing Unix Time; the following will convert Unix Time to a Julian Date so that you can use the edtime DIESEL function (which requires a Julian Date value):

Code - Auto/Visual Lisp: [Select]
  1. (defun UnixDate ( value format )
  2.     (menucmd (strcat "m=$(edtime," (rtos (+ 2440588 (/ value 86400.0)) 2 15) "," format ")"))
  3. )
« Last Edit: April 30, 2012, 06:47:57 AM by Lee Mac »

Lupo76

  • Bull Frog
  • Posts: 343
Re: Vlisp e date
« Reply #12 on: April 30, 2012, 07:26:51 AM »
Perfect!  :lmao:
Thanks Lee!  :wink: