Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interested in date script ?! 1

Status
Not open for further replies.

thieg

IS-IT--Management
Jul 1, 2002
5
0
0
US
Hi all,

I tried to create this script without success, any help
would be really appreciated :)

I receive a date from a form, typically 14-jul-2002, and I want to know which day it is and the associated week number. Clearly, I want to be able to say that this date is the Monday of the 3rd week of the month.

Also, in the opposite way, I have the day (let say Tuesday), a week number (let say 4) a month (March) and a year (2002), I want to have in result the exact date (19-Mar-2002) or a null if it doesn't exist.

Unfortunately, I didn't find anything similar on the internet...

Thx for ur help & interest.
 
There is something useful at that link!! --


I took a crack at a similar problem a year ago, found it easier to hardcode (my problem covered 6 specific months of the current year only) the answer and move on. Two pieces of information sufficient to map a calendar month onto a 6 row by 7 column array are the # of days in the month and the day of the week of the month's first day. The "roll your own" methods for calculating those two pieces of information involve data tables, dividing by 4 and perhaps by 400, lots of calculation, a multitude of ways to screw up. (Hard code it and move on.)

But JavaScript gives us a Date object where someone else has already sweated the details. Day of the week? Date.getDay(). # days in a month? Apparently its a one liner. (I haven't tested the solution at the link but it looks like the JavaScript implementors helpfully convert constructor calls with day 32 to a legal date in the following month. If this works it is a very clever implementation and a very useful shortcut.)

Knowing that March 2002 has 31 days, that March 1, 2002 is a Friday [day of the week '5' from getDay()] is sufficient information to map the month correctly, extract the contents of the third column (Tuesday) of the fourth row (week 4), test it for validity (19).

JavaScript and a handy link provide the raw material to solve your problem (and mine next time ...) Hope it works!
 
I've already created a navigable calendar component (in JavaScript) which accounts for the week-of-month. Take a look at and notice how easily you can select the "2nd Sunday" or "last Tuesday"

As you navigate the calendar using its various controls, it updates the week-of-month selector accordingly.

:: richard.renfrow@juno.com
 
Hi,

This is what I use on my site:

<SCRIPT LANGUAGE=&quot;Javascript&quot;>
var dayarray=new Array(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;)
var montharray=new Array(&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;)

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym=&quot; &quot;+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn=&quot;AM&quot;
if (hours>=12)
dn=&quot;PM&quot;
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes=&quot;0&quot;+minutes
if (seconds<=9)
seconds=&quot;0&quot;+seconds
//change font size here
var cdate=&quot;<small><font color='FFD700' face='Arial'><b>&quot;+dayarray[day]+&quot;, &quot;+montharray[month]+&quot; &quot;+daym+&quot; / &quot;+year+&quot;   &quot;+hours+&quot;:&quot;+minutes+&quot;:&quot;+seconds+&quot; &quot;+dn
+&quot;</b></font></small>&quot;
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById(&quot;clock&quot;).innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function showtime(){
if (document.all||document.getElementById)
setInterval(&quot;getthedate()&quot;,1000)
}
</SCRIPT>

<BODY onLoad=&quot;showtime()&quot;>

You can see it in action at my site:
Hope this helps! NATE
spyderix.gif

design@spyderix-designz.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top