Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: How to set shortdate format using JavaScript in ASP?


Message #1 by lcp97@h... on Fri, 21 Jun 2002 17:27:06
var ndate =3D new Date();
var month =3D ndate.getMonth() + 1;
var day =3D ndate.getDate();
var year =3D ndate.getYear();

var dstr =3D month + "/" + day + "/" + year;

submit [dstr] variable in a form post or whatever to a field in your db
with a type of [string].

J. Scot
IronSpire Inc.


-----Original Message-----
From: lcp97@h... [mailto:lcp97@h...]
Sent: Friday, June 21, 2002 4:09 PM
To: javascript
Subject: [javascript] RE: How to set shortdate format using JavaScript
in ASP?


I am not sure about your second answer however I think that this idea
would be better (less code). Could you give more details??

TIA!!

> question 1: answer
function padout(number){  =3D20
	return (number < 10) ? '0' + number : number;=3D20
}
function ampm(time) {
    var hours =3D3D time.getHours(), minutes =3D3D =3D
padout(time.getMinutes());
    var adjhours =3D3D (hours =3D3D=3D3D 0) ? 12 : ((hours < 13) ? hours 
:
hours-12);
	return ((adjhours < 10) ? ' ' : '') + adjhours + ':' + minutes +
((hours < 12) ? ' am' : ' pm');
}

These functions may help you =3D3D)

question 2: answer
You could submit a custom built short date to just a text field in the
db for easy retrieval later =3D3D)

J. Scot
IronSpire Inc.


-----Original Message-----
From: lcp97@h... [mailto:lcp97@h...]
Sent: Friday, June 21, 2002 3:48 PM
To: javascript
Subject: [javascript] RE: How to set shortdate format using JavaScript
in ASP?


J.

It is now much better (thank you), however there are two issues:
1.) how should I do to avoid different message sizes? For instance:
2002-6-18 16:53:22
2002-6-7 15:13:5

2.) in PowerDynamo I didn't have to deal with anything for the date
(it=3D20
showed as stored in the db). Is there a simpler way to accomplish
that=3D20
also in JavaScript? Since the output can be "huge" I am trying to avoid
to=3D20
much code to be executed.

TIA!!


> wtemp =3D3D3D new Date(String(dbConn.Fields(0).Value));
month =3D3D3D (wtemp.getMonth()+1)+ "/";
day =3D3D3D wtemp.getDate() + "/";
year =3D3D3D wtemp.getYear();
Response.Write("<TD class=3D3D3D'"+tdclass+"'>"+wtemp+"</TD>");

Something along these lines should work.
you'll have to extract the hour, minute, seconds the same way if you
want them.

J. Scot =3D3D3D)
IronSpire Inc.

-----Original Message-----
From: lcp97@h... [mailto:lcp97@h...]
Sent: Friday, June 21, 2002 3:23 PM
To: javascript
Subject: [javascript] RE: How to set shortdate format using JavaScript
in ASP?


Didn't work with toLocaleString. I used

wtemp =3D3D3D dbConn.Fields(0).Value;=3D3D20
wtemp =3D3D3D String(wtemp).toLocaleString;
Response.Write("<TD class=3D3D3D'"+tdclass+"'>"+wtemp+"</TD>");

It still returns the data in the same format: Tue Jun 18 10:08:36 CDT
2002

Still in the same boat!!
TIA


> maybe if you try toLocaleString Date method;
or build the string the way you want extracting
  year, month, day, hour, minutes, and seconds from the database value
this way the result isn't affected by the user's configuration :)

HTH

> -----Original Message-----
[...]
> I am getting a date value from a Sybase 5.5 database table. I want
to=3D3D20
> display it in a shortdate format however I ONLY get the long=3D3D20
> one such as=3D3D20
> Fri Jun 21 10:48:58 CDT 2002.
>=3D3D20
> I am using ASP with Javascript. My code for that is:
>=3D3D20
> wtemp =3D3D3D dbConn.Fields(0).Value;=3D3D20
> Response.Write("<TD class=3D3D3D'"+tdclass+"'>"+wtemp+"</TD>");
>=3D3D20
> I wanna see the value:  2002-06-21 10:48:58=3D3D20
>=3D3D20
> What I should try???

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3D3D3Dnosim/theprog
r
a=3D
m
m=3D3D
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3D3D3Dnosim/theprog
r
a=3D
m
m=3D3D
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3D3D3Dnosim/theprog
r
a=3D
m
m=3D3D
e
r-20
---
Change your mail options at http://p2p.wrox.com/manager.asp or=3D3D20

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3D3Dnosim/theprogra
m
m=3D
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3D3Dnosim/theprogra
m
m=3D
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3D3Dnosim/theprogra
m
m=3D
e
r-20
---
Change your mail options at http://p2p.wrox.com/manager.asp or=3D20

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20

  Return to Index