[Javascript] ARGH! Help with Dates!

allard schripsema allard-schripsema at procergs.rs.gov.br
Fri Jan 2 14:42:03 CST 2004


Hi,

this line makes the trouble:
  cDate = new Date(myDate.getTime() + days*24*60*60*1000);

try this: 
function addDays(myDate,days) {
     days=days*24*60*60*1000
     cDate = new Date(myDate.getTime() + days);
     dy = cDate.getDate();
     mn = cDate.getMonth();
     y = cDate.getYear();
     h = cDate.getHours();
     m = cDate.getMinutes();
     s = cDate.getSeconds();
     nDate = mn + "/" + dy + "/" + y + " " + h + ":" + m + ":" + s;
     return nDate;
}

must be a js-bug, i can´t see why it didn´t work with your code
Be aware that January is month 0 ! 


  ----- Original Message ----- 
  From: Dave Stoltz 
  To: '[JavaScript List]' 
  Sent: Friday, January 02, 2004 4:12 PM
  Subject: [Javascript] ARGH! Help with Dates!


  I am trying desperately to get the date in Javascript in EXACTLY this format: 1/4/2004 5:45 PM 

  This seems painfully difficult....I have the following 2 functions working, except the month comes back as 0 all the time.
  If the dropdown box called "Priority" is "Normal", I want to add 2 days to the current date/time, and if Priority is "Emergency" I want to add 1 day to the current date/time.

  Here are my functions, why is the month coming back as 0 !!!!???

  Thanks for any help!

  <script language="javascript">
  <!--
  function addDays(myDate,days) {
       cDate = new Date(myDate.getTime() + days*24*60*60*1000);
       dy = cDate.getDate();
       mn = cDate.getMonth();
       y = cDate.getYear();
       h = cDate.getHours();
       m = cDate.getMinutes();
       s = cDate.getSeconds();
       nDate = mn + "/" + dy + "/" + y + " " + h + ":" + m + ":" + s;
       return nDate;
  }
  function setdueby(){
       var1 = form1.Priority.value;
       if(var1=='Normal'){
       var2 = (addDays(new Date(),2));
       form1.dueby.value=var2;
       }
       if(var1=='Emergency'){
       var3 = (addDays(new Date(),1));
       form1.dueby.value=var3;
   }}
  -->
  </script>


------------------------------------------------------------------------------


  _______________________________________________
  Javascript mailing list
  Javascript at LaTech.edu
  https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040102/36d70009/attachment.htm>


More information about the Javascript mailing list