Reply
javascript version of VBscript dateadd
Old 06-08-2006, 05:47 AM javascript version of VBscript dateadd
Skilled Talker

Posts: 95
I think the subject says it all.

But what i'm looking for is a way to add months on to a date.

i.e i have a variable set to 60 months i want to add this to a date

for example
  • 01/01/2006 which in vbscipt i do useing dateadd which in this case would return 01/01/2011 not 01/61/2006
Is the a function or a simple way of doing this in javascript
higginbt is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 06-08-2006, 07:35 AM Re: javascript version of VBscript dateadd
Skilled Talker

Posts: 95
Ok so this is what i've come up with.

function date_addmonth(strDate,duration)
{
var mydate = strDate
var day =(mydate.substring(0,2))
var month = (mydate.substring(3,5))
var year = (mydate.substring(6,10))
alert(day)
alert(month)
alert(year)
month = Number(month) + duration
var testdate = new Date(month +"/" + day +"/" + year )
alert(testdate)
}

This function reads in a date in a string format dd/mm/yyyy i.e English date not US date. I then use substring to seperate out the day month year.

Add the duration and then build up a new date with the day month swicth round

Last edited by higginbt : 06-08-2006 at 07:36 AM.
higginbt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to javascript version of VBscript dateadd
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11324 seconds with 13 queries