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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time in External File

Status
Not open for further replies.

UncleCake

Technical User
Joined
Feb 4, 2002
Messages
355
Location
US
I have this script that returns the day an date, which worked great when it was inside a html document. I pulled it out of the html and put it in a JavaScript file, which writes the header on my pages, but it isn’t working. Can anyone see any problems?


Here is what is in the JavaScript file:


document.write(&quot;<script>&quot;);
document.write(&quot;<!--&quot;);
document.write(&quot;var mydate=new Date()&quot;);
document.write(&quot;var year=mydate.getYear()&quot;);
document.write(&quot;if (year < 1000)&quot;);
document.write(&quot;year+=1900&quot;);
document.write(&quot;var day=mydate.getDay()&quot;);
document.write(&quot;var month=mydate.getMonth()&quot;);
document.write(&quot;var daym=mydate.getDate()&quot;);
document.write(&quot;if (daym<10)&quot;);
document.write(&quot;daym='0'+daym&quot;);
document.write(&quot;var dayarray=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')&quot;);
document.write(&quot;var montharray=new Array('January','February','March','April','May','June','July','August','September','October','November','December')&quot;);
document.write(&quot;<font size='2' face='Verdana' color='#0066CC'>'+dayarray[day]+', '+montharray[month]+' '+daym+', '+year+'</font>&quot;);
document.write(&quot;//-->&quot;);
document.write(&quot;</script>&quot;);
 
TRy using this:
Code:
var mydate=new Date()
var theYear=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
  if (daym<10)
    daym=&quot;0&quot;+daym
  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;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;07&quot;,&quot;08&quot;,&quot;09&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;)
    document.write(&quot;<font face='Geneva, Arial, Helvetica, san-serif' color='black'><h6> &quot;+dayarray[day]+&quot;<br>&quot;+montharray[month]+&quot;/&quot;+daym+&quot;/&quot;+theYear+&quot;</h6></font>&quot;)
Put this in an extertnal JS file, and call it in the HTML fil as:
<script language=&quot;Javascript&quot; src=&quot;date.js&quot;></script>
This line is what outputs the results: document.write(&quot;<font face='Geneva, Arial, Helvetica, san-serif' color='black'><h6> &quot;+dayarray[day]+&quot;<br>&quot;+montharray[month]+&quot;/&quot;+daym+&quot;/&quot;+theYear+&quot;</h6></font>&quot;), you can change basicaly all the HTML atributes, or add new ones...
I have not failed; I merely found 100,000 different ways of not succeding...
 
Thanks GUJUm0deL, it worked great!

-Uncle Cake
 
No problemo... I have not failed; I merely found 100,000 different ways of not succeding...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top