Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date convert help

 
Loges waran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi code ranch,

I need to get one logic.

For example, I have one Date 03-30-2012. My period is 10 days.

I need to subtract the number 10(Dynamic values may change) from 03-30-2012... The result should be 03-20-2012.

Can anybody help me for fixing this bug.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What bug? You showed no code for a bug.

Did you look at the Date object? It has methods to get the date and its parts. https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

Eric
 
Loges waran
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hereer is the code:

var notifperiod = a.value;
var expirydate = b.value);
var notifdate = new Date(b.value);
var date1=notifdate.getDate();
notifdate.setDate(date1-notifperiod);

var notifdatefinal = (notifdate.getMonth()+1)+"-"+notifdate.getDate()+"-"+notifdate.getYear();

a.value=notifdatefinal;


In this code, when i enter April 5 as Expiry date and notification period as 10 days. it shows the result of 02-25-2012 It is not showing 03-25-2012.
But for if the difference between Expiry date & notif period occurs in the same month means its working fine.


Suggest me to solve this problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic