[Javascript] ARGH! Help with Dates!

Dave Stoltz dstoltz at shh.org
Fri Jan 2 13:47:51 CST 2004


Thanks - then actually I just need to add 1 do the month, then my code
works...
 
THANK YOU!

  _____  

From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
On Behalf Of allard schripsema
Sent: Friday, January 02, 2004 3:42 PM
To: [JavaScript List]
Subject: Re: [Javascript] ARGH! Help with Dates!


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 <mailto:dstoltz at shh.org>  
To: '[JavaScript List]' <mailto:javascript at LaTech.edu>  
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/8f474eed/attachment.htm>


More information about the Javascript mailing list