Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Help changing date & time javascript to just date...
Old 06-06-2006, 10:26 PM Help changing date & time javascript to just date...
Skilled Talker

Posts: 79
Trades: 0
Hi there, I have the following code...

<script language="JavaScript" type="text/javascript">
<!-- hide from old browsers
var curDate = new Date()
document.write(curDate.toLocaleString())
//-->
</script>


Which outputs the following...

Wednesday, 7 June 2006 11:25:04 AM

Is it possible to change the code so that it outputs just the date...

Eg: Wednesday, 7 June 2006

Mally
malhyp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-06-2006, 10:47 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
This should work:
<script language="JavaScript" type="text/javascript">

var d=new Date();
var monthname=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December");
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();

</script>
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 10:55 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Then put this code exactly where you want the date to show.

<script language="JavaScript" type="text/javascript">
document.write(TODAY); </script>
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 11:15 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Oops. Sorry I forgot you want the day as well

Here is the code:

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function GetDay(intDay){
var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")
return DayArray[intDay]
}

function GetMonth(intMonth){
var MonthArray = new Array("January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December")
return MonthArray[intMonth]
}
function getDateStrWithDOW(){
var today = new Date()
var year = today.getYear()
if(year<1000) year+=1900
var todayStr = GetDay(today.getDay()) + ", "
todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
todayStr += ", " + year
return todayStr
}
//-->
</SCRIPT>

And here is how you implement it:

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
document.write(getDateStrWithDOW())
//-->
</SCRIPT>

These things are easy to find on the WEB.
http://www.javascriptmall.com/jsc/jsC4Udate.htm
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-09-2006, 06:33 AM Re: Help changing date & time javascript to just date...
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
Trades: 0
You could also try this:

function getDate()
{
var d, s = "Today's date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getYear();
return(s);
}
__________________
I think, therefore I am..... I think.

Last edited by scottfree; 06-09-2006 at 06:34 AM..
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 06-09-2006, 07:33 AM Re: Help changing date & time javascript to just date...
Skilled Talker

Posts: 79
Trades: 0
Thanks, they were all good.
malhyp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help changing date & time javascript to just date...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45146 seconds with 12 queries