473,785 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need to get same day last year in javascript!

If anyone can help me out with a good way to do this in javascript I
would greatly appreciate it.

I need to compute three dates in javascript - all of which relate to a
given date, say todays date.

I need to calculate:
1.
same day last year(that is, if today is friday, i want the date of the
friday 52 weeks ago)
2.
same day last week( same as above but only 1 week ago)
3.
same date last year

thanks
Jul 20 '05 #1
2 9563
Lee
John said:

If anyone can help me out with a good way to do this in javascript I
would greatly appreciate it.

I need to compute three dates in javascript - all of which relate to a
given date, say todays date.

I need to calculate:
1.
same day last year(that is, if today is friday, i want the date of the
friday 52 weeks ago)
2.
same day last week( same as above but only 1 week ago)
3.
same date last year


Sounds like a homework assignment to me.

var today=new Date();
var week=new Date().setDate( today.getDate()-7);
var dayyear=new Date().setDate( today.getDate()-7*52);
var dateyear=new Date().setYear( today.getFullYe ar()-1);

Jul 20 '05 #2
JRS: In article <66************ ************@po sting.google.co m>, seen
in news:comp.lang. javascript, John <my********@yah oo.com> posted at Fri,
20 Feb 2004 08:58:53 :-
I need to calculate:
1.
same day last year(that is, if today is friday, i want the date of the
friday 52 weeks ago)

As it happens, 31 December this year will be a Friday. 52 weeks before
it is 2 January, of this year, making the fault obvious. Sometimes you
need to go back 53 weeks; and there are various possible ways of doing
that.

D.setDate(D.get Date()-7*52)

will do what you parenthetically ask for, for any Date Object D.

2.
same day last week( same as above but only 1 week ago)
D.setDate(D.get Date()-7)

3.
same date last year


Not necessarily possible. Which day will you want to reach by going
back a year from the end of next week? Of course, you could go to the
previous instance of the same date, which was 2000-02-29.
Read the newsgroup FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3240
by: Amanda | last post by:
Hi, hope you can help me with this one. If I want to get the date a page has been last modified, I can do something like .. document.write("<b>Last updated: "+document.lastModified+"</b>"); Can I use this to display the date that other pages were last modified - eg other pages on my website? I want my index.htm to display the last modified date of other pages on the
8
5108
by: timmy_dale12 | last post by:
I need help with this one. I have a function that pastes a row. In each row i am pasting a link which is to call a date picker javascript function. This is the code that pastes the link : link = document.createElement('a'); link.href ="javascript:show_calendar('document.form1.date',document.form1.date.value);"; img = document.createElement('img'); img.setAttribute("src","H:Diverse\\cal.gif"); link.appendChild(img);
13
3620
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not sure if it can be done, but all help welcomed. E.g. I have December and would like to see the last 2 weeks.. So this doesnt mean the last 15 days. What i mean by this is...
2
2937
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
7
41075
by: laredotornado | last post by:
Hello, Does anyone know how (or if) I can figure out the last time a web page was last modified if my only access to it is via HTTP (a web browser). Right now, I'm looking at "Page Info" options. There is a "Modified" field but I think that is telling me the time that the file was downloaded to my machine. Any advice is greatly appreciated, - Dave
6
5740
by: news | last post by:
I need some concise, easy to grok examples of what .Net (preferably C#.Net) has over just using old ASP or PHP with JavaScript. See, I'm a PHP guy, and while I started server-side scripting with ASP, I hate it. But last year I had the opportunity to work with a company that was developing sites in VB.Net. And I was wowed! The stuff they could do was really nice and impressive, and I got the chance to learn a little about datagrids. Was...
0
3963
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
2
4069
by: micangello | last post by:
i need ideas on what my final year project can be about i have studied 2 years of pure math (advanced calculus and algebra, topology, statistics..... ) i then switched ot computer science now in in my last year in Computer Science i have taken courses in Numerical analysis Operation Research
3
2163
by: aashishn86 | last post by:
var weekend = ; var weekendColor = "#e0e0e0"; var fontface = "Verdana"; var fontsize = 1; var gNow = new Date(); var ggWinCal; isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false; isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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 we have to send another system
2
3665
muto222
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.