Changing months to weeks - newbie

A

Anole

I wonder if somebody with patience for a novice could help me translate the
following to days or weeks from months:

now = new Date();
visitMonth = now.getMonth();
if(visitMonth <"10"){visitMonth="0"+visitMonth}
thisVisit = now.getYear() +""+ visitMonth +""+ now.getDate();

thisYear = publishDate.slice(6,10);
thisMonth = publishDate.slice(3,5);
thisDate = publishDate.slice(0,2);
thisPubl = thisYear + thisMonth + thisDate;

If you don't want to make it too easy, you could just give me some good
"hints"...

Thanks in advance...

anole
 
M

McKirahan

Anole said:
I wonder if somebody with patience for a novice could help me translate the
following to days or weeks from months:

now = new Date();
visitMonth = now.getMonth();
if(visitMonth <"10"){visitMonth="0"+visitMonth}
thisVisit = now.getYear() +""+ visitMonth +""+ now.getDate();

thisYear = publishDate.slice(6,10);
thisMonth = publishDate.slice(3,5);
thisDate = publishDate.slice(0,2);
thisPubl = thisYear + thisMonth + thisDate;

If you don't want to make it too easy, you could just give me some good
"hints"...

Thanks in advance...

anole

You probably want:
a) "now.getMonth()+1" not "now.getMonth()".
b) "now.getFullYear()" instead of "now.getYear()"

Where is "publishDate" declared?

What do you mean "translate the following to days or weeks from months"?
 
M

McKirahan

McKirahan said:
You probably want:
a) "now.getMonth()+1" not "now.getMonth()".
b) "now.getFullYear()" instead of "now.getYear()"

Where is "publishDate" declared?

What do you mean "translate the following to days or weeks from months"?

Don't know what you mean by "translate the following to days or weeks from
months" but the following may be of some help (save and run as-is); watch
for word-wrap:


<HTML>
<HEAD>
<TITLE>anole1.htm</TITLE>
<script language="javascript" type="text/javascript">
<!--
var now = new Date();
var nowYr = now.getFullYear();
var nowMo = now.getMonth()+1;
if (nowMo < 10) nowMo = "0" + nowMo;
var nowDa = now.getDate();
if (nowDa < 10) nowDa = "0" + nowDa;
var thisVisit = "" + nowYr + nowMo + nowDa;
alert("ccyymmdd = " + thisVisit);

var publishDate = "18/12/2003";
var thisYear = publishDate.slice(6,10);
var thisMonth = publishDate.slice(3,5);
var thisDate = publishDate.slice(0,2);
var thisPubl = thisYear + thisMonth + thisDate;
alert("dd/mm/ccyy = " + publishDate + "\nccyymmdd = " + thisPubl);
// -->
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
 
A

Anole

Thank you, McKirahan;

I haven't gotten a chance to play with it, but I'm hoping that works. It's
a snippet from some code somebody sent me to put the "new" in front of
updates on a page that have occurred within the past month. Since the
people I'm doing it for check in more often than that, I was hoping to alter
it so it would reflect, say, items updated in the past one or two weeks...

Since I didn't write it (or entirely understand how it worked), I was hoping
to have the assistance of a kindly Samaritan like you...

Thanks again,

anole
 
A

Anole

Thank you, McKirahan;

I haven't gotten a chance to play with it, but I'm hoping that works. It's
a snippet from some code somebody sent me to put the "new" in front of
updates on a page that have occurred within the past month. Since the
people I'm doing it for check in more often than that, I was hoping to alter
it so it would reflect, say, items updated in the past one or two weeks...

Since I didn't write it (or entirely understand how it worked), I was hoping
to have the assistance of a kindly Samaritan like you...

Thanks again,

anole
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
I haven't gotten a chance to play with it, but I'm hoping that works. It's
a snippet from some code somebody sent me to put the "new" in front of
updates on a page that have occurred within the past month. Since the
people I'm doing it for check in more often than that, I was hoping to alter
it so it would reflect, say, items updated in the past one or two weeks...

Since I didn't write it (or entirely understand how it worked), I was hoping
to have the assistance of a kindly Samaritan like you...


Read the newsgroup FAQ; it will teach you how to format news replies,
and you could indirectly learn something about dates too.


Avoid date strings of the forms mm/dd/[yy]yy and dd/mm/[yy]yy on the
Web; they might cause confusion. Only 1.5 countries use mm/dd/yyyy.
Use yyyy/mm/dd or 'yyyy MON dd'.

For your now-better-revealed question : ISTM that the best way to
measure recent-ness is in absolute time.

Assuming that you do not upload inconsequential updates, therefore, the
correct approach must be to access the lastModified string, convert it
to a defects-fixed Date Object, subtract from new Date(), and compare
with the time allowed - from your words, maybe with 864e6 to allow ten
standard days-worth. That approach, unlike others, will be unaffected
by user's time zone and Summer time status.

However, to be really elegant, and if this is work-related, you could
count only working days in the period.

See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top