www.webdeveloper.com
Results 1 to 8 of 8

Thread: loops that show weekday, date and month in 2013

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    loops that show weekday, date and month in 2013

    Hi!

    I am new at JavaScript and would like some help pls..
    I want to write out weekday, date and month for 2013.
    exempel it should write:

    tisdag 1 januari
    onsdag 2 januari
    torsdag 3 januari
    fredag 4 januari

    Excuse my English, stil Learning.. =)

    ______________________

    function nameOfDay() {

    var day=new Array(7);
    day [0]="Sunday";
    day[1]="monday";
    day[2]="tuesday";
    day[3]="wendsday";
    day[4]="thuersday";
    day[3]="friday";
    day[4]="saturday";

    return day;
    {


    function nameOfMonth()
    }
    var month=new Array(12);
    month[0]="January";
    month[1]="February";
    month[2]="March";
    month[3]="April";
    month[4]="May";
    month[5]="June";
    month[6]="July";
    month[7]="August";
    month[8]="September";
    month[9]="October";
    month[10]="November";
    month[11]="December";
    }
    return month;
    }

    function DayInMonth (month, year) {
    var date = new Date(year, month, 1);
    var days = [;
    console.log('month', month, 'date.getMonth()', date.getMonth())
    while (date.getMonth() === month) {
    days.push(new Date(date));
    date.setDate(date.getDate() + 1);

    }
    return days;
    }

    for (var day = 0; i < 7; i++)
    for(var month = 0; i <= 11; i++)
    (j=1; j<month; j++)

    document.writeln(day + month + daysInmonth(j));

  2. #2
    Join Date
    Oct 2013
    Location
    Utah
    Posts
    13
    To clarify, are you looking for something that displays the current date of the month?

  3. #3
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    By looking at your question and by examining your attempt of writing a code I'm not sure if this is what you are looking for but here's the code:

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    	<title> Untitled </title>
    	<meta charset="utf-8">
    	<script>
    		var date = new Date(), date2 = new Date(), weekNo,
    			Month = [
    					 "January",
    					 "February",
    					 "March",
    					 "April",
    					 "May",
    					 "June",
    					 "July",
    					 "August",
    					 "September",
    					 "October",
    					 "November",
    					 "December"];
    		
    		date = new Date(date.getFullYear(),0,1,0,0,0,0); //makes code generic ie.you could use it in 2014,2015...
    		weekNo = Math.floor((date2 - date) / 604800000 ); // 1 week = 604800000 milliseconds
    		
    		document.write(
    					   "Date: " + date2.getDate() + "<br />" +
    					   "Month: " + Month[date2.getMonth()] + "<br />" +
    					   "Week number: " + weekNo + "<br />" +
    					   "Year: " + date2.getFullYear() + "<br />" +
    					   "Full date: " + date2.toString()
    					   );
    	</script>
    </head>
    <body>
    </body>
    </html>
    Note: Weeks are not counted according to the ISO standard. According to the ISO-8601 weeks starts on Monday and ends on Sunday!!
    Last edited by tech_soul8; 11-08-2013 at 06:47 PM.

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    You could simply grab a date reference like
    Code:
    var d = new Date();
    var n = d.toDateString();
    which will output a date like... Sat Nov 09 2013

    You could then use that as is or process it further by matching the beginning date ref to an array to then get the full name of the day of week.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Nov 2013
    Posts
    2
    the code has to write all Days of the year (2013) ..

    start from :
    Tuesday 1 januari

    end at:
    tisdag 31 december

    The function that are used are dayInMonth, nameOfWeekday, NameOfMonth.

  6. #6
    Join Date
    Nov 2013
    Location
    London, United Kingdom
    Posts
    15
    You code is not in the working condition because of few syntax errors. Would you like to know how to fix them yourself with our help or your main interest just to get the task done and you are not not interested in improving your coding skills?

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,318
    So here goes with this idea...
    Code:
    for(dates=1; dates<365; dates++){
    	v = returnDateFormatted(dates,"Jan 01,2013");
    	console.log("Date : "+v);
    }
    
    function returnDateFormatted(dates,dobjStr){
        var d = new Date(dobjStr);
        d.setDate(dates);
        dow = ["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur"][d.getDay()] +"day";
        mth =["Januray","Feburay","March","April","May","June","July","August","September","October","November","December"][d.getMonth()];
    	yr = d.getFullYear();
    	dateStr = [dow,d.getDate(),mth,yr].join(" ");
    	return dateStr;
       }
    Feed the function with a date number and a date String and the function returns a formatted date from what is passed.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    This is my attempt:

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    	<title> Untitled </title>
    	<meta charset="utf-8">
    	<style type="text/css">
    		body {
    			width: 1200px;
    			margin: 0 auto;
    			padding-top: 15px;
    		}
    		
    		table, td, th {
    			border: 1px solid black;
    			border-collapse: collapse;
                            text-align: center;
    		}
    		
    		table {
    			width: 275px;
    		}
    		
    		caption {background: yellow;}
    		
    		.main_header {
    			font-size: 16px;
    			font-weight: bold;
    			color: red;
    		}
    		.table {
    			width: 280px;
    			margin-right: 15px;
    			margin-bottom: 25px;
    			float: left;
    		}
    		.row {
    			clear: both;
    			padding-left: 10px;
    		}
    	</style>
    </head>
    <body>
    	<h1 style="color: red; text-align: center;">Year - 2013</h1>
    	<div class="row">
    		<div id="d0" class="table"></div>
    		<div id="d1" class="table"></div>
    		<div id="d2" class="table"></div>
    		<div id="d3" class="table"></div>
    	</div>
    	<div class="row">
    		<div id="d4" class="table"></div>
    		<div id="d5" class="table"></div>
    		<div id="d6" class="table"></div>
    		<div id="d7" class="table"></div>
    	</div>
    	<div class="row">
    		<div id="d8" class="table"></div>
    		<div id="d9" class="table"></div>
    		<div id="d10" class="table"></div>
    		<div id="d11" class="table"></div>
    	</div>
    	<script>
    		function DATES_TABLE()
    		{
    		}
    		
    		DATES_TABLE.prototype.init = function(year)
    		{
    			var table =
    				"<table>" +
    				"<caption>" + year +"</caption>" +
    				"<thead>" +
    				"<tr>" +
    				"<td class='main_header'>Day</td>" +
    				"<td class='main_header'>Date</td>" +
    				"<td class='main_header'>Month</td>" +
    				"<td class='main_header'>Year</td>" +
    				"</tr>" +
    				"</thead><tbody>";
    			return table;
    		}
    		
    		DATES_TABLE.prototype.createTable = function(year)
    		{
    			var
    				date = new Date(year,0,1), weekDays = [], dates = [],
    				months = [], i, j = 0, tmpTable = this.init(date.getFullYear()),
    				tables = [], index;
    				
    			for (i = 0; i <= 11; i++)
    			{
    				var x = date.getMonth();
    	
    				while (date.getMonth() <= 11)
    				{	
    					weekDays[j] = date.toDateString().substr(0,3);
    					dates[j] = date.getDate();
    					months[j] = date.toDateString().substr(4,3);
    					date.setDate(date.getDate() +1);
    					j++
    					if ((x < date.getMonth()) || ((x == 11) && (date.getMonth() == 0))) break;
    				}
    				tables[i] = this.createBody(weekDays,dates,months,year,tmpTable);
    				weekDays = [], months = [], dates = [], j = 0;
    			}
    			
    			for (index in tables)
    			{
    				document.getElementById('d' + index).innerHTML = tables[index];
    			}
    			return;
    		}
    		
    		DATES_TABLE.prototype.createBody = function(w,d,m,y,table)
    		{
    			var i;
    				
    			for (i = 0; i < d.length; i++)
    			{
    				table += "<tr>" +
    							"<td>" + w[i] + "</td>" +
    							"<td>" + d[i] + "</td>" +
    							"<td>" + m[i] + "</td>" +
    							"<td>" + y + "</td>" +
    						 "</tr>";
    			}
    			table += "</tbody></table>";
    			return table;
    		}
    	
    		var o = new DATES_TABLE();
    		o.createTable(2013);
    	</script>
    </body>
    </html>
    Last edited by tech_soul8; 11-10-2013 at 12:36 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles