Jump to content

Dates


monkeytooth

Recommended Posts

Maybe its cause I am just that tired and burnt out currently.. But I am trying to write a function to display

 

<day>, <month> <day number><suffix>, <year>

Example: Sunday, October 17th, 2010

 

However I seemed to screw myself up somewhere in the process and lost my <month> in the script. <month> is coming up and "undefined" but I can't figure it out, im burnt right now. I need an extra pair of eyes to help me out here, thanks in advance.

 

<script type="text/javascript">
<!--
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var d = new Date();
var curr_day = d.getDay();
var curr_date = d.getDate();
var sup = "";

if (curr_date == 1 || curr_date == 21 || curr_date ==31){sup = "st";}
else if (curr_date == 2 || curr_date == 22){sup = "nd";}
else if (curr_date == 3 || curr_date == 23){sup = "rd";}
else{sup = "th";}

var curr_month;
var curr_year;

if((d.getMonth()+6) > 12){curr_month = d.getMonth()+6;curr_year = d.getFullYear();}
else{curr_month = d.getMonth()-6;curr_year = d.getFullYear()+1;}

document.write(d_names[curr_day] + ", " + m_names[curr_month] + " " + curr_date + "<SUP>"+ sup + "</SUP>, " + curr_year);
//-->
</script>

Link to comment
https://forums.phpfreaks.com/topic/216055-dates/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.