PDA

View Full Version : Show date only...?



Chris P. Bacon
10-31-2006, 10:40 AM
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!

codeexploiter
10-31-2006, 12:51 PM
<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>


If you want to show only the current date then the above code will do the job.

I wonder why you are using a lengthy code just to show date

Chris P. Bacon
10-31-2006, 02:21 PM
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.

VatsaL
10-31-2006, 05:48 PM
<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>

there you go.

Twey
10-31-2006, 05:57 PM
This should serve you:
<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>
<small><font color='000000' face='Arial'><b>Ouch. Never use presentational HTML. Also, all colours in HTML notation must be prefixed with a hash sign (#).
var year=mydate.getYear()
if (year < 1000)
year+=1900Instead, try .getFullYear().
<script>The type attribute is required.

Chris P. Bacon
10-31-2006, 06:22 PM
Thanks alot guys! I saved them all, so I can learn how its working. :)