Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to count number of days

  1. #1
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default How to count number of days

    I tried to calculate the number of days to Christmas without success.

    Your helps are much appreciated.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: How to count number of days

    Load julian.lsp from Express Tools. Use DTOJ to Converts AutoCAD calendar dates and time to Julian dates, subtract to get the difference.

  3. #3
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to count number of days

    Thanks Tom.
    This is what I have. Am I right?
    Code:
    (defun c:Test ()
    (c:date)
    (setq ChristmasIsComing (- (dtoj 20131225) (dtoj 20130205)))
    (prompt (strcat "WOW! Christmas is coming in "
    (rtos ChristmasIsComing 2 0)
    " days!")
    )
    )

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How to count number of days

    Quote Originally Posted by BeKirra View Post
    Thanks Tom.
    This is what I have. Am I right?
    Code:
    (setq ChristmasIsComing (- (dtoj 20131225) (dtoj 20130205)))
    Code:
    (setq ChristmasIsComing (- (dtoj 20131225)
    			   (dtoj (fix (getvar 'cdate)))))

  5. #5
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: How to count number of days

    Not sure what you're looking for, but here's a java ChristmasCountdown.htm file you can save to your computer and open with a browser just for fun.
    HTML Code:
    <html>
    <head>
    <TITLE>Christmas Countdown</TITLE>
    
    <script language="javascript">
    <!--
    var count = new Date("December 25, 2013 07:00");
    var timeUp = "Time to open presents!"
    
    var timerID;
    var timerRunning = false;
    var today = new Date();
    var persec = 0;
    var permin = 0;
    var perhour = 0;
    var perday = 0;
    var peryear = 0;
    var secsRemain = 0;
    var yearRemain = 0;
    var dayRemain = 0;
    var minRemain = 0;
    var timeRemain = 0;
    var expire = 0;
    
    function stopclock (){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;
    }
    
    function startclock () {
    stopclock();
    showtime();
    }
    
    function showtime () {
    today = new Date();
    /*count.setYear(today.getYear());*/
    persec = 1000;
    permin = 60*persec;
    perhour = 60*permin;
    perday = 24*perhour;
    peryear = 365*perday;
    
    expire = (count.getTime() - today.getTime())
    
    /*Seconds*/
    secsRemain = (Math.floor(expire/persec))%60;
    /*Minutes*/
    minRemain = (Math.floor(expire/permin))%60;
    /*Hours*/
    hoursRemain = (Math.floor(expire/perhour))%24;
    /*Days*/
    daysRemain = Math.floor(expire/perday)%365;
    /*Years*/
    yearRemain = Math.floor(expire/peryear);
    
    /*Handle single digits*/
    if (hoursRemain < 10) hoursRemain = "0" + hoursRemain;
    if (minRemain < 10) minRemain = "0" + minRemain;
    if (secsRemain < 10) secsRemain = "0" + secsRemain;
    
    /*Time*/
    
    timeRemain ='';
    timeRemain = yearRemain + ":" + daysRemain + ":" + hoursRemain + ":" + minRemain + ":" + secsRemain;
    
    //if (yearRemain) { timeRemain += yearRemain; }
    //if (daysRemain) { timeRemain += daysRemain; }
    //if (hoursRemain) { timeRemain += hoursRemain; }
    //if (minRemain) { timeRemain += minRemain; }
    //if (secsRemain) { timeRemain += secsRemain; }
    //timeRemain = yearRemain + daysRemain + hoursRemain + minRemain + secsRemain;
    //timeRemain = daysRemain + hoursRemain + minRemain + secsRemain;
    //timeRemain = hoursRemain + minRemain + secsRemain;
    
    document.clock.face.value = timeRemain;
    timerID = setTimeout("showtime()",1*persec);
    timerRunning = true;
    
    if (expire <= 0){
    document.clock.face.value = timeUp;  // choose either "time" or "timeUp"  (without quotes)
    stopclock();
    }
    
    }
    // -->
    </script>
    </head>
    
    
    
    <!-- <body bgcolor="#FFFFFF" text="#000000" link="#b09040" vlink="#806010" alink="#FF0000"> -->
    <body bgcolor=green text=orange link="#b09040" vlink="#806010" alink="#FF0000">
    
    </tr>
    <tr><td colspan=3 valign=top width=449>
    
    
    <!-- Start the Underhandle -->
    
    <center>
    
    <p>
    &nbsp;
    
    </p>
    
    
    <!-- <p><strong><b><font size="2">NEXT UP...</font><br> -->
    <font size="5"><i>Christmas Morning!</i></font><font face="Arial" size="3"><br><i>
    December 25, 2013 07:00am</i></font></b>
    <!-- </strong></p> -->
    <form NAME="clock">
    <p><b><font face="Arial" size="4">Better be good until<br>
    </font></b><strong><font face="Arial" size="2">
    Years:Days:Hours:Minutes:Seconds</font><br>
    <font size="4">
    <!-- <input TYPE="text" SIZE="12" NAME="face" style="font-size: 14pt; background-color: #800000; color: #FFFF00"></font><br> -->
    <input TYPE="text" SIZE="11" NAME="face" style="font-size: 14pt; background-color: green; color: orange"></font><br>
    <script LANGUAGE="JavaScript">
    <!--
    startclock()
    // --> </script></p>
    </form>
    
    <p>
    &nbsp;
    </p>
    
    </b></center>
    </p>
    
    </td></table>
    <!-- End the Underhandle -->
    
    <!-- All the stuff below the handle goes here -->
    
    </BODY>

  6. #6
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to count number of days

    Thanks to Tom again.
    Your code is really fun! At this point I think it may be good to write a code for event reminder.
    And thanks to pbejse.

    BTW, I know there is different way to get the calendar day.
    Which one is better for my case and why? for example:
    Code:
    (menucmd "M=$(edtime,$(getvar,date),YYYYMODD)")
    and
    Code:
    (getvar 'cdate)
    Thanks again.

  7. #7
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How to count number of days

    Quote Originally Posted by BeKirra View Post
    BTW, I know there is different way to get the calendar day.
    Which one is better for my case and why? for example:

    Thanks again.
    (menucmd "m=$(edtime,$(getvar,date),yyyymodd)"):<-- The result is a string value

    To use the result for your purpose , you need to convert the string to a valid value for arithmetic function, in this case (-) subtraction
    (atoi (menucmd "m=$(edtime,$(getvar,date),yyyymodd)"))) --- > 20130204

    (getvar 'cdate) <---- result is Real number--> 2.01302e+007
    (fix (getvar 'cdate)) <---- result is integer --> 20130204

    HTH

  8. #8
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: How to count number of days

    Hadn't thought about diesel.
    Code:
     (menucmd "M=$(-,20131225,$(edtime,$(getvar,date),YYYYMODD))")
    gives you # of days till Christmas.
    Good reference for diesel is http://www.crlf.de/Dokumente/Diesel/Diesel.html
    I use it extensively in CUI's.

  9. #9
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: How to count number of days

    Thanks again.
    Now I agree with using "fix". It is really good for getting calendar date in the lisp code.

    And to Tom, I am afraid that I have to use "dtoj" from (c:date) because the following won't return an actual number of days but "1019" days:
    Code:
    (menucmd "M=$(-,20131225,$(edtime,$(getvar,date),YYYYMODD))")
    Hope my understanding is correct.

  10. #10
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: How to count number of days

    Quote Originally Posted by BeKirra View Post
    Thanks again.
    Now I agree with using "fix". It is really good for getting calendar date in the lisp code.

    And to Tom, I am afraid that I have to use "dtoj" from (c:date) because the following won't return an actual number of days but "1019" days:
    Code:
    (menucmd "M=$(-,20131225,$(edtime,$(getvar,date),YYYYMODD))")
    Hope my understanding is correct.
    Guess I should have error checked that.
    Code:
    (menucmd "M=$(-,2456652,$(fix,$(getvar,date)))")
    returns "322"

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 14
    Last Post: 2009-05-22, 02:21 AM
  2. Replies: 13
    Last Post: 2007-03-19, 11:37 AM
  3. Count the Number of Groups Scheduled
    By david.fannon in forum Revit Architecture - General
    Replies: 0
    Last Post: 2007-02-06, 07:51 PM
  4. Count the number of Blocks in a drawing file
    By ajtrahan in forum AutoCAD Fields
    Replies: 9
    Last Post: 2006-06-02, 02:52 PM
  5. Routine to count the number of Layouts in a drawing
    By pgastelum77763 in forum AutoLISP
    Replies: 9
    Last Post: 2005-07-07, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •