Subtract A Day To Date Object Using 'myDate - 1'

May 29, 2007

Am i breaking any rules when I loop dates like

// Determine Memorial Day
intFlag = 0;
memDayHol = new Date (currentYear, 4, 31);
while (intFlag == 0) {
if (memDayHol.getDay() == 1) {intFlag =1;}
else {memDayHol = memDayHol - 1;}

I can find no docs that one can use the '+' operator directly on a date
object, and it assumes adding/subtracting a day(s). Is this deprecated

View 10 Replies


Subtract N Days From Current Date?

Nov 10, 2010

I have the following function that will subtract n number of days from todays date. The problem is that it always returns the the wrong calculate date. The month is wrong.

see if you can spot my mistake:


function returnDate(ndays){
var dayOfTheWeek = now.getDay();
now.setTime(now.getTime() - nDays * 24 * 60 * 60 * 1000);
alert(now); // returns current date
alet(now.getYear() + "/"+now.getMonth()+"/"+now.getDate()) // returns new calculated date

View 5 Replies View Related

Create A New Template Object That Inherits From The Built In Date Object

Oct 6, 2011

Is there any way at all to create a new template object that inherits from the built in Date object so as to be able to add new methods to that child object without adding them to the built in Date object? I've tried everything I can think of and as far as I can tell it keeps referencing the Date function instead of the Date object and so doesn't work.

View 3 Replies View Related

Date Object

Jul 23, 2005

How do check for a date object?

<script type="text/javascript">
var d=new Date()
var arr=new Array("Jun 5",d,"Mar 16")
if(arr[i] != Date()) // is string or is not date object
document.write(arr[i] + "<br>")

View 1 Replies View Related

Date () Object In Safari

Jul 20, 2005

According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation.

I am interested in dates from 1500 to 1901, as far as I can determine, there are 14 possible calendar variations.

Year starts on Sun, Mon..... Leap year starts on Sun, Mon..

I can label these early year "types" as a number between 0 and 13.

Let's say 2005 is type 5, and that 1655 is too. (In both years Jan 1 falls on a Saturday)

I'm trying to create a function that will identify the "type" of year.

function getYearType(year){
return Number // number between 0 and 13

View 7 Replies View Related

Extend The Constructor For The Date Object?

Jul 9, 2010

How to extend the constructor for the date object of the javasccript so that whenever a call is made to the constructor, I want to perform a particular action? Basically how to define wrappers for default javascript methods or objects like Date() so that I can perform some action and then invoke the original method? So basically if I have something like var a = new Date(); I want it to (say) alert the value of the date everything Date() is called and then execute the default date constructor.

View 3 Replies View Related

Date Object - Value Assignment Not Reference ?

Feb 7, 2011

The goal is for selectedDay to be assigned the value of the system variable Mainpackage.subclass0.subclass1.firstDay and then incremented by two days. Mainpackage.subclass0.subclass1.firstDay needs to be unchanged.

Important system variable in red. To be 'manipulated and used' variable in green. Even with an intermediary, third, dummy variable it doesn't work:

Console log is:

It doesn't work in my webapp : All variables change at the same time.

View 4 Replies View Related

Create A Date Object From An ISO8601string?

Jun 15, 2011

I was wondering how you would create a javascript Date object from an ISO8601 string? We have done this successfully in FF4, but not IE.

If we try the following in FF4 it works:

alert(new Date("20091107T12:15:00))

In IE it returns:


What would be the Date standard used in JavaScript and AJAX from the server to the client? We were thinking about using UTC

View 1 Replies View Related

Convert String To Date Object ?

Dec 16, 2005

Is it possible to convert a String of date like 12/25/2005 01:00PM to a Date object?

View 14 Replies View Related

Date Object, Consistent UTC Time?

May 3, 2010

I have a question about what the most certain method to obtain the correct UTC time in javascript is.On my forum, there is a countdown clock, that should show the same amount, wherever the user is located. I use UTC in javascript to get the current time, but I have trouble getting consistent results.I have tried two methods:Method 1:

var d = new Date();
var localTime = d.getTime();


View 7 Replies View Related

Date Object Acceptable Strings?

Jan 29, 2010

I am trying to find a format for a string that could be used to instantiate a Date object which would include only a month and a year.I can't find documentation on what formats of dates are accepted.

View 6 Replies View Related

Unexpected Result From Date Object Manipulation?

Mar 6, 2009

In the below, I would expect this to return the number of milliseconds since the epoch. Instead, it's generating a massive negative number. I presume I've gone wrong with the set[Blah] methods.

javascript Code:

var date_text = '2009-03-06 12:00:00';
var d_tried = new Date();


View 3 Replies View Related

Does Object Gets Date From User Local Time?

Oct 23, 2010

I was wondering if it is true that the Date object gets its date from the user's local time, if so, could the user "hack" the time by adjusting his local time?

View 6 Replies View Related

Windows 7 (X64) Date Object - No Expected Results

Jul 23, 2011

The Date Object returns GMT
Firefox gives: Date {Sat Jul 23 2011 18:02:12 GMT+0100 (Cen)}
Chrome gives: Sat Jul 23 2011 18:02:12 GMT+0100 (Eastern Standard Time)
I was expecting: Sat Jul 23 2011 14:02:12 GMT+0600 (Eastern Standard Time)
My Windows XP (x86) PC gives me expected results.

View 1 Replies View Related

Date Object In Brazil Time Zone

Oct 18, 2011

I am facing issue in below code for Brisilia time zone.(GMT-3). Issue comes in October month only. It is going tobig loop. I am not getting how Date object is behaving here.


View 1 Replies View Related

Date Object - Cannot Get Current Month With Print Function

May 28, 2009

I was working on Date() object of javascript. When I write:
today=new Date();
Here everything was correct but when I print month then I got currentmonth-1 that if the currentmonth is 5 then t get 4. If the current month is 07 then I get 06. At last I worked by adding 1 with month like month+1.

View 1 Replies View Related

Date Object Function - Variables Coming Up Undefined

Apr 27, 2010

I am trying to use my date Object function to get the date from the comp but my variables in my function are coming up undefined.

Here is my function:
function displayTime() {
var currentTime, hour, minute, second, range, m, s
currentTime = new Date()
var hourInt = currentTime.getHours()
var minuteInt = currentTime.getMinutes()
var secondInt = currentTime.getSeconds()

if (hourInt > 12) {
range = "PM"
hourInt -= 12
} else {
range = "AM"
hour = String(hourInt)

if (minuteInt < 10) {
m = String(0) + String(minuteInt)
} minute = m
if (secondInt < 10) {
s = String(0) + String(secondInt)
} second = s
document.timeForm.timeBox.value = hour + ":" + minute + ":" + second + " " + range
alert(hour + ":" + minute + ":" + second + " " + range)

View 1 Replies View Related

Custome Date Object With PHP-like Text-parsed Output

Dec 6, 2002

Well, this is acutally a couple different scripts. First is the custom date object myDate which retrieves pretty much every value that you'd need from a date and sets it as a property. If no argument is supplied, the current time and date is used. If you do supply an argument, you can send an existing javascript Date object, or a string that is compatible with declaring a normal javascript Date object.

The 2nd part of this script is the method getDate (and some accompanying String methods) that allow you to retrieve the date as a string by passing it a format string just like the PHP date() ( function accepts. The code posted below includes sufficient (I think) examples to help you understand what is going on. You will notice that I didn't duplicate EVERY code over from PHP, and a few are slightly different. Those that I left out I felt weren't very necessary, or I didn't feel like doing the algorithm for them :D.

Both myDateObj.getDate() and PHP's date() allow you to include text into the string that you don't want parsed, but each handles it differently. In PHP, you need to escape characters normally with a backslash. For getDate you need to proceed each character with a pipe "|". So, instead of$dateStr = date("Day z");as it would be in PHP, you would usevar d = new myDate();
var dateStr = d.getDate("D|a|y| z");There are more examples of how this works below.

Note: There is also a nice arrayReplace() method for strings that is handy for doing multiple replace() operations all at once, so I guess this is really like 3 handy scripts ;)

<meta http-equiv="expires" content="0">
<script type="text/javascript">

/*** First Part of Script, the custom date object ***/

function myDate(dateStr) {
if (typeof dateStr != 'undefined') {
var d = new Date(dateStr);
this.dateString = dateStr;
else if (typeof dateStr == 'object')
var d = dateStr;
var d = new Date();
var months = ['January','February','March','April','May','June','July','August','September','October','November',' December'];
var weekDays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var monthDays = [31,28,31,30,31,30,31,31,30,31,30,31];

this.epoch = d.getTime();
this.epochS = Math.round(this.epoch / 1000);
this.year4 = d.getFullYear();
this.year2 = parseInt(this.year4.toString().substring(2));
this.leap = (this.year4 % 400 == 0) ? true : (this.year4 % 4 == 0 && this.year4 % 100 != 0) ? true : false;
if (this.leap) monthDays[1]++;
this.mnth = d.getMonth();
this.month = this.mnth + 1;
this.month_2 = leadingZero(this.month);
this.monthName = months[this.mnth];
this.monthNameShort = this.monthName.substring(0,3);
this.days = monthDays[this.mnth];
this.dy = d.getDay(); = this.dy + 1;
this.dayName = weekDays[this.dy];
this.dayNameShort = this.dayName.substring(0,3); = d.getDate();
this.date_2 = leadingZero(;
this.suffix = ( % 10 == 1 ) ? "st" : ( % 10 == 2) ? "nd" : ( % 10 == 3) ? "rd" : "th";
this.hours24 = d.getHours();
this.hours24_2 = leadingZero(this.hours24)
this.hours12 = (this.hours24 == 0) ? 12 : (this.hours24 > 12) ? this.hours24-12 : this.hours24;
this.hours12_2 = leadingZero(this.hours12);
this.minutes = d.getMinutes();
this.minutes_2 = leadingZero(this.minutes);
this.seconds = d.getSeconds();
this.seconds_2 = leadingZero(this.seconds);
this.millis = d.getMilliseconds();
this.ampm = (this.hours24 == 0) ? "am" : (this.hours24 >= 12) ? "pm" : "am";
this.GMTstring = d.toGMTString();
this.offset = d.getTimezoneOffset();

function leadingZero(num) {
return (num < 10) ? "0" + num : num.toString();

myDate.prototype.getDayOfYear = function() {
var total = 0;
var monthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
if (this.leap) monthDays[1]++;
for (var i=0; i<this.mnth; total += monthDays[i++]) {}
total +=;
return total;

/*** Second part of script, the PHP-like parsed output ***/

myDate.prototype.getDate = function(str) {
var p = ['a','A','B','d','D','F','g','G','h','H','i','I','j','l','L','m','M','n','O','r','s','S','t','T','U', 'w','W','Y','y','z','Z'];
var r = new Array();
var i = 0;
var delChar = "|";
var sNull = "null".delimit(delChar)
r[i++] = this.ampm.delimit(delChar);
r[i++] = this.ampm.toUpperCase().delimit(delChar);
r[i++] = sNull;
r[i++] = this.date_2;
r[i++] = this.dayNameShort.delimit(delChar);
r[i++] = this.monthName.delimit(delChar);
r[i++] = this.hours12;
r[i++] = this.hours24;
r[i++] = this.hours12_2;
r[i++] = this.hours24_2;
r[i++] = this.minutes_2;
r[i++] = sNull;
r[i++] =;
r[i++] = this.dayName.delimit(delChar);
r[i++] = (this.leap)?1:0;
r[i++] = this.month_2;
r[i++] = this.monthNameShort.delimit(delChar);
r[i++] = this.month;
r[i++] = this.offset;
r[i++] = this.GMTstring.delimit(delChar);
r[i++] = this.seconds_2;
r[i++] = this.suffix.delimit(delChar);
r[i++] = this.days;
r[i++] = sNull;
r[i++] = this.epochS;
r[i++] = this.dy;
r[i++] = sNull;
r[i++] = this.year4;
r[i++] = this.year2;
r[i++] = this.getDayOfYear();
r[i++] = sNull;
for (i=0; i<p.length; i++)
p[i] = "/" + p[i] + "(?!|)/g";
return str.arrayReplace(p, r).replace(/|/g,"");

String.prototype.arrayReplace = function(arrP, arrR) {
var p, s = this;
for (var i=0; i<arrP.length; i++) {
var flags = arrP[i].substring(arrP[i].lastIndexOf("/")+1);
var regex = arrP[i].substring(1,arrP[i].lastIndexOf("/"));
p = new RegExp(regex, flags);
s = s.replace(p, arrR[i]);
return s;

String.prototype.delimit = function(char) {
var s = "";
for (var i=0; i<this.length; i++) {
s += this.charAt(i) + char;
return s;



<script type="text/javascript">

/*** Example using current date/time ***/

var md1 = new myDate();
document.write(md1.getDate("l jS of F Y h:i:s A")+"<br>");
document.write(md1.getDate("T|o|d|a|y| i|s| m.d.y")+"<br>");
document.write(md1.getDate("D M j G:i:s Y")+"<br>");
document.write("It " + (md1.leap?"is":"is not") + " a leap year<br>");
document.write("The unix epoch occurred " + md1.epochS + " seconds ago");

/*** Example using javascript Date object as argument ***/

var d1 = new Date(2000, 01, 02, 15, 15, 15);
var md2 = new myDate(d1);
document.write(md2.getDate("l jS of F Y h:i:s A")+"<br>");
document.write(md2.getDate("T|o|d|a|y| i|s| m.d.y")+"<br>");
document.write(md2.getDate("D M j G:i:s Y")+"<br>");
document.write("It " + (md2.leap?"is":"is not") + " a leap year<br>");
document.write("The unix epoch occurred " + md2.epochS + " seconds ago");

/*** Example using Date object compatible string as argument ***/

var md3 = new myDate("December 10, 1978 12:23:00");
document.write(md3.getDate("l jS of F Y h:i:s A")+"<br>");
document.write(md3.getDate("T|o|d|a|y| i|s| m.d.y")+"<br>");
document.write(md3.getDate("D M j G:i:s Y")+"<br>");
document.write("It " + (md3.leap?"is":"is not") + " a leap year<br>");
document.write("The unix epoch occurred " + md3.epochS + " seconds ago");

View 4 Replies View Related

JQuery :: Changing Datepicker's Date Format Of Selected Date From Date Picker

Mar 16, 2011

I am having difficulty trying to change the format of selected date from date picker. This is a test so my code is very simple. Here it is.


View 1 Replies View Related

Date Object - Assigned The Value Of The System Variable Mainpackage.subclass0.subclass1?

Feb 7, 2011

The goal is for selectedDay to be assigned the value of the system variable Mainpackage.subclass0.subclass1.firstDay and then incremented by two days. Mainpackage.subclass0.subclass1.firstDay needs to be unchanged.

Important system variable in red.

To be 'manipulated and used' variable in green.

Even with an intermediary, third, dummy variable it doesn't work:


//Declarations and instantiations
var systemDate = new Date();
var selectedDay = new Date();[code]....

View 1 Replies View Related

Subtract Using Random Arrays

Jun 12, 2006

Heres my most current code. I have it where, onClick on an image it calls this. and it works, but the hp keeps restarting, like they all minus from 100, instead of the number that prieviously minused from 100. For xp: 100-9=91, is the first, the second, 100-72=28 instead of 91-72. How do i fix

var myhp;
function takehits()
var dmg= new Array()

var rndtake=Math.floor(Math.random()*5);

I want to have it where, you have an aray, and u have a number value that you want the number value, to be subtracted by one of the numbers in the array. And u lets say the array has 5 choices. Code:

View 4 Replies View Related

JQuery :: Date Range - Start Date And End Date Text Boxs

Feb 6, 2010

I have a start date and end date text boxs. What I would like to achieve is when a submit button is clicked all the available dates between start and end dates should be displayed together with 3 check boxes next to each date (please see below). I am just wondering whether that'sachievablewith jquery, and if so, how I might be able to implement this.

Start date End date

View 8 Replies View Related

How To Auto Subtract Two Text Values

Mar 16, 2011

I am trying to change the script below from adding the values to subtracting without much luck.
<script type="text/javascript" language="javascript">
function autocalc(oText) {
if (isNaN(oText.value)) //filter input {
alert('Numbers only!');
oText.value = '';
} var field, val, oForm = oText.form, netincome = a = 0;
for (a; a < arguments.length; ++a) //loop through text elements {
field = arguments[a];
val = parseFloat(field.value); //get value
if (!isNaN(val)) //number? {
netincome += val; //accumulate
oForm.netincome.value = netincome; //out

View 1 Replies View Related

JQuery :: Access Index Of Item And Add/subtract From It?

Jan 10, 2012

I have an image gallery where every image has an index number ("data-index"). How do I access that index number when the image is "current" and then add +1 when it's "next" or subtract -1 when it's "previous"? Below is part of my code.


View 2 Replies View Related

Add Or Subtract From The Numeric Value Of Hour[0] Based On Timezone

Oct 15, 2009

Take a variable...

var time = "12:00"
split it...
var hour=time.split(":");

...then add or subtract from the numeric value of hour[0] based on timezone.

EST = -5
PST = -8

What would be the best way of doing this?

View 20 Replies View Related

Setinterval - Use Local Storage To Set A Value In My Web App - Subtract A Number ?

Apr 19, 2011

What Ive done is use local storage to set a value in my web app.

Then my next task was to write said value on my page (This took me hours but finally got it done).

My next task is using Setinterval(or what ever the correct way to solve my problem) to subtract a number (lets use "1" for this example) Every 5 seconds from the local storage value.So basically After I click the button. Value is set and displayed. After another button is click. Every 5 seconds the localstorage is subtraced by 1. I think the code im looking for is similar to this


View 1 Replies View Related

Copyrights 2005-15, All rights reserved