View Full Version : date time format

12-19-2006, 08:12 PM
how to display day of the week and month in word not number

day of the week: Mon or Tue etc..
month: Nov, Dec


12-19-2006, 08:31 PM
For just english? An easy way is

var dayName = [

then if you have a var dayNum (between 0-6) just



12-19-2006, 09:08 PM

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">

function init(){

alert(new Date().toLocaleString());
alert(new Date());

var shortDay = new Date().toString().split(" ")[0];
var longDay = new Date().toLocaleString().split(",")[0];
var shortMonth = new Date().toString().split(" ")[1];
var longMonth = new Date().toLocaleString().split(",")[1].replace(/\d+|\s+/g,"");

document.forms[0].dayName.value = longDay;
document.forms[0].monthName.value = longMonth;

document.getElementById('demo').innerHTML = "Today is a " + shortDay + " in " + shortMonth;


<style type="text/css">

body {background-color:#eae3c6;margin-top:60px}
form {width:230px;margin:auto}
fieldset {width:230px;background-color:#f0fff0;border:1px solid #87ceeb}
legend {font-family:times;font-size:14pt;color:#00008b;background-color:#87ceeb;padding-left:3px;padding-right:3px;margin-bottom:5px}
label {font-family:times;font-size:12pt;color:#00008b;padding:5px}
.submitBtn {font-family:tahoma;font-size:10pt;display:block;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px}
#demo {font-family:tahoma:font-size:14pt;color:#0000cd;font-weight:bold;background-color:#ff8c00;adding:5px;text-align:center;margin:10px}

<div id='demo'></div>
<form method="post" action="">
<legend>Day and Month</legend>
<label>Day Name:&nbsp;&nbsp&nbsp;&nbsp&nbsp;<input type='text' name='dayName' size='15' readonly></label>
<label>Month Name: <input type='text' name='monthName' size='15' readonly></label>
<input type='submit' name='submit' value="Submit" class='submitBtn'>

12-19-2006, 10:15 PM
I don't know if it is useful or not but Ancora inspired me to make mine more flexible. So using his date parsing code I put together this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script type="text/javascript">
function setDiv(div, s) {
document.getElementById(div, s).innerHTML = s;

function findDayName(n, bIsShort) {
if (n < 1 || n > 7) return("Unknown");
var dt = new Date();
dt.setFullYear(1995, 0, n);
var shortDay = dt.toString().split(" ")[0];
var longDay = dt.toLocaleString().split(",")[0];

return((bIsShort) ? shortDay : longDay);

function findMonthName(n, bIsShort) {
if (n < 1 || n > 12) return("Unknown");
var dt = new Date();
dt.setFullYear(1995, n - 1, 1);
var shortMonth = dt.toString().split(" ")[1];
var longMonth = dt.toLocaleString().split(",")[1].replace(/\d+|\s+/g,"");

return((bIsShort) ? shortMonth : longMonth);

function findNames() {
var dayNum = parseInt(document.f.daynum.value);
var monthNum = parseInt(document.f.monthnum.value);
var isShort = document.f.isshort.checked;
setDiv("adiv", "The day is " + findDayName(dayNum, isShort));
setDiv("bdiv", "The month is " + findMonthName(monthNum, isShort));
<form name="f" action="#" onsubmit="return(false);">
<label>Enter day number (1-7) <input type="text" name="daynum" value="1" /></label>
<br />
<label>Enter month number (1-12) <input type="text" name="monthnum" value="1" /></label>
<br />
<label>Check for short name <input type="checkbox" name="isshort" /></label>
<button onclick="findNames();">Find Names</button>
<br />
<div id="adiv"> </div>
<div id="bdiv"> </div>


12-19-2006, 10:59 PM
hi thanks guys
i have my page here

how should i interate with what i have

12-19-2006, 11:50 PM
It depends what you want. The date turned in to text? Seperate columns for day of the week and month? Something else?

12-20-2006, 12:06 AM
i like to make the date to display
in something like this format Nov 1, Tue
instead of right now 11/1

12-20-2006, 04:47 AM
A bit easier than your first question. Try changing this function

Event.prototype.getDay = function () {
var arr = this.date.toString().split(" ");
arr.length = 3;
return arr.join(" ");


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum