Forums

This topic is locked

How do I get date like: 09/10/01 using asp Date()?

Posted 09 Oct 2001 11:06:29
1
has voted
09 Oct 2001 11:06:29 Kevin Abbott posted:
How do I get date like: 09/10/01 using asp Date() function?

Replies

Replied 10 Oct 2001 09:47:06
10 Oct 2001 09:47:06 Viktor Farcic replied:
Use Set Locale ID server behavior.

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
How do I get date like: 09/10/01 using asp Date() function?


<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Replied 11 Oct 2001 11:10:39
11 Oct 2001 11:10:39 Kevin Abbott replied:
How do I do that?

I can get the date just my doing

var MyDate = Date();

and then in my page do:

&lt;%=MyDate%&gt;

But it shows has a long string.
All I want is 00/00/00 format.

I've searched the web and can only find a function call FormatDateTime but that can only be used with VB not JS.

Replied 11 Oct 2001 19:50:20
11 Oct 2001 19:50:20 B. B. replied:
Hey! The following can be used if you are running Jscript at the server location.

The Date object in JS has a bunch of date methods that you can use to build your date in a desired format. You must specify the
RUNAT="SERVER" parameter in your script tag's language declaration or you will get the date from the client machine.

Following is some sample code.

Had to comment the script tag and also had to remove the "&lt;" and "&gt;" to show in this forum.

//script Language="JavaScript"
//RUNAT="SERVER"

// Get the current date and time
RightNow = new Date();
var mth = RightNow.getMonth() + 1
var aday = RightNow.getDay()
var curhr = RightNow.getHours()
var curyy = RightNow.getYear()
var curyyyy = RightNow.getFullYear()
var alphaday = "";

// For alpha days JS starts at 0 for Sunday
// thru 6 for Saturday then
// you will need to create an if code block
// to value the alpha day from
// the numeric value that JS passes back to
// the page
// Based on the day or date you can then
// redirect to another page if needed

// The best year method is getFullYear then
// pull out the two position
// year. The getYear results return the
// difference of the current
// year minus 1900 which yields 101 which
// you do not want.

if (aday == 4)
{ alphaday = "Thursday";
location.href = "test_redirect.asp" }

document.write("Today's date is " + mth + "/"
document.write(+ RightNow.getDate() + "/" + RightNow.getYear() + "."
document.write("&lt;p&gt;The full year is " + curyyyy + "now &lt;/p&gt;"
document.write(" You entered this page at: " + RightNow.getHours() + " hours"
document.write(" " + RightNow.getMinutes() + " minutes and " + RightNow.getSeconds() + " seconds"
document.write("&lt;/br&gt;Today's day is: " + alphaday)

You can have JS and Visual Basic scripts on the same page if necessary.
Hope this helps. Thanks!



Reply to this topic