473,473 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help in subtracting dates please....

13 New Member
hi, i need help i want to subtact 30 days from current date. here is my sample code but its not working.

Expand|Select|Wrap|Line Numbers
  1. var currentTime = new Date()
  2. var month = currentTime.getMonth() + 1
  3. var day = currentTime.getDate() - 30
  4. var year = currentTime.getFullYear()
  5. var ddownload = month + "-" + day + "-" + year
  6.  
  7. document.write(ddownload)
  8.  
the sample date today : 08-09-2007
but when i subtracted 30 days from date today the output is : 8--21-2007

please can anyone help me? thanks.
Aug 9 '07 #1
2 1207
r035198x
13,262 MVP
hi, i need help i want to subtact 30 days from current date. here is my sample code but its not working.

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate() - 30
var year = currentTime.getFullYear()
var ddownload = month + "-" + day + "-" + year

document.write(ddownload)

the sample date today : 08-09-2007
but when i subtracted 30 days from date today the output is : 8--21-2007

please can anyone help me? thanks.
This is not Java. Moved to Javascript forum.
Aug 9 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Please use CODE tags when posting code.

9 - 30 = -21 (that's why you're getting -21)

To solve this problem, use the setDate() method:
Expand|Select|Wrap|Line Numbers
  1. currentTime.setDate(currentTime.getDate()-30);
Get the day, month and year values after setting the date.
Aug 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
1
by: Jesse O | last post by:
I have two date fields, start_date and end_date. I'd like to subtract the two dates, and come up with a number (the number of difference between the two dates). What function is there to do...
2
by: End Around | last post by:
I am creating a time-based art web site that will show a different html page depending on the client side local date. I also prefer that the top page doesn't literally redirect to, say 7.htm for...
2
by: Eddie | last post by:
When I subtract dates, I can't figure out what I get out. I first I thought it was in seconds, but that's not it. Then I figured maybe HHMMSS, but that does not seem to be it too. How can I...
4
by: Jcs_5920 | last post by:
Hello All, I was reading some of the posts trying to learn about date coding schemes used in old DOS programs with no luck, so I though I'd ask the group for help. These are the HEX values and...
27
by: Josh | last post by:
I work for a small hotel. They don't want to invest in a good front desk program and the paper system that is being used is not working. It is complete chaos at the moment. I want to make a...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
4
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform that value to an attribute in the XML output...
31
by: Spiro Trikaliotis | last post by:
Hello, I have a question regarding subtracting a pointer from another one. Assume I have two pointers p1 and p2, which both point to a memory area obtained with malloc(). Assume p1 = p2 + some...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.