Hey,
I got this script on my website: http://www.dynamicdrive.com/dynamicindex6/clock2.htm I have the script that shows both time and date, but I want it to ONLY show date. Anyone know what to add/remove from the script to do this? Thanks!
Hey,
I got this script on my website: http://www.dynamicdrive.com/dynamicindex6/clock2.htm I have the script that shows both time and date, but I want it to ONLY show date. Anyone know what to add/remove from the script to do this? Thanks!
If you want to show only the current date then the above code will do the job.Code:<script type="text/javascript"> var dt = new Date(); var d = dt.getDate(); var day = (d < 10) ? '0' + d : d; var m = dt.getMonth() + 1; var month = (m < 10) ? '0' + m : m; var yy = dt.getYear(); var year = (yy < 1000) ? yy + 1900 : yy; document.write(day + "-" + month + "-" + year); </script>
I wonder why you are using a lengthy code just to show date
Thanks, but I need it to appear like: Tuesday, 31st October. I use that script because it loads fast, and shows the date how I want it, I just dont want the time. If anyone knows another script that shows the date like above, please link to it, that would be great.
there you go.Code:<script> 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="0"+daym var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December") document.write("<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+"</b></font></small>") </script>
This should serve you:Code:<script type="text/javascript"> var DAYS = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], MONTHS = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], SUFFIXES = { 1 : "st", 2 : "nd", 3 : "rd", 21 : "st", 22 : "nd", 23 : "rd", 31 : "st", 'default' : "th" }, d = new Date(); document.write(DAYS[d.getDay()] + ", " + d.getDate() + (SUFFIXES[d.getDate()] || SUFFIXES['default']) + MONTHS[d.getMonth()]); </script>Ouch. Never use presentational HTML. Also, all colours in HTML notation must be prefixed with a hash sign (#).<small><font color='000000' face='Arial'><b>Instead, try .getFullYear().var year=mydate.getYear()
if (year < 1000)
year+=1900The type attribute is required.<script>
Last edited by Twey; 10-31-2006 at 06:03 PM.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Thanks alot guys! I saved them all, so I can learn how its working.![]()
Bookmarks