Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you get the date using just HTML 2

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Our WEB site does not support .asp pages
I am creating a UPS tracking page for our customers to track by Reference number, UPS WEB site requires the date too.
I hard coded a Date it in to test, and it works fine.
When I add the VB script it just ignores it.
Need to get the current date and break it apart into Month Day Year

Any ideas at all?

TIA


DougP, MCP, A+
 
The following test page will set 3 form fields with the day, month and year when the page loads. It cannot be done using HTML alone -- so I have employed a little javascript.

Note that this solution requires javascript be enabled on the user's browser... and that it gets the date from the user's local computer (so if their clock is set wrong then they may get odd results).
Code:
<html>
<head>
<title>Break up date example</title>
<script type="text/javascript">
<!--
function setDateInfo() {
	var myFrm = document.forms['myForm'];
	var today = new Date();
	myFrm.day.value = today.getDate();
	myFrm.month.value = today.getMonth() - 0 + 1;
	myFrm.year.value = today.getFullYear();
}
window.onload = setDateInfo;
//-->
</script>
</head>
<body>
<form name="myForm" action="">
	<fieldset>
		<input type="text" name="day" value=""/>
		<input type="text" name="month" value=""/>
		<input type="text" name="year" value=""/>
	</fieldset>
</form>
</body>
</html>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Yeah Baby
Stars are flying !!!!
You da Man !!!!
Whoa Yeah
Thanks Thanks Thanks

DougP, MCP, A+
 
BabyJeffy, how do I subtract 30 days for the "FROM..." dates?

Code:
function setDateInfo()
{
    var myFrm = document.forms['myForm'];
    var today = new Date();
    myFrm.FromPickupDay.value = today.getDate();
    myFrm.FromPickupMonth.value = today.getMonth() - 0 + 1;
    myFrm.FromPickupYear.value = today.getFullYear();

    myFrm.ToPickupDay.value = today.getDate();
    myFrm.ToPickupMonth.value = today.getMonth() - 0 + 1;
    myFrm.ToPickupYear.value = today.getFullYear();

}

DougP, MCP, A+
 
Date has a constructor which takes a value in milliseconds as an argument and returns the date equivalent to that number. I can't remember from what point in history the millisecond count begins, but if you just need a date 30 days prior today, you can go back 30 days worth of milliseconds from today as so:

var thirtyDaysAgo = new Date(new Date() - (30*24*60*60*1000));

Obviously the 30*... is the conversion of 30 days to milliseconds.

'hope that helps.

--Dave
 
Well that piece of code return this

Code:
myFrm.ToPickupMonth.value =  new Date(new Date() - (30*24*60*60*1000));

Wed Aug 17 14:06:04 EDT 2005
which is 24 hours ahead



DougP, MCP, A+
 
DooH !!!
its September, Man time flys
Sorry I thought it was August

But I need to get an 8 in the following box
myFrm.FromPickupMonth.value =

how do I format this Wed Aug 17 14:06:04 EDT 2005


DougP, MCP, A+
 
Code:
var thirtyDaysAgo = new Date(new Date() - (30*24*60*60*1000));
myFrm.ToPickupMonth.value =  thirtyDaysAgo.getMonth() - 0 + 1;
//ABOVE: same as what Jeff did for the other date.

'hope that helps!

--Dave
 
Ok Great
how 'bout a star !!!

I modified it to this

Code:
    myFrm.FromPickupMonth.value = new Date(new Date() - (30*24*60*60*1000)).getMonth() - 0 + 1;

DougP, MCP, A+
 
Thanks for the star!

Your modified code will work of course. The "longer" version is for readability (if you re-visit the code, it will be easier for you to remember what you were doing) and also in case you needed the date from 30 days ago for any other reason other than retrieving the month.

'glad it worked out!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top