Date format in form field and send to access database

L

Loa

How do I create a form field that defaults to current date using format
mm/dd/yyyy?
Would also like to be able to change the date if necessary and would like to
have it validated to correct format mm/dd/yyyy
Any info will be greatly appreciated
 
T

Trevor L.

Loa said:
How do I create a form field that defaults to current date using
format mm/dd/yyyy?
Would also like to be able to change the date if necessary and would
like to have it validated to correct format mm/dd/yyyy
Any info will be greatly appreciated

Here is some code which puts today's date in a form fleld in format
mm/dd/yyyy

Changing the date and clicking on "Check" will give a rudimentary date
check.
It will either display the full UTC date or NaN.
It will throw out days or months without leading zeroes.
But it will also accept 01/32/2006 as 1 Feb 2006.
and 01/118/2006 as 11 Jan 2006 (but thows out 01/70/2006)
For better date checkers, see other posts here, especially those by Dr John
Stockton.

Or you could write one yourself.
Just code this into JavaScript :)
Thirty days hath September,
April June and November.
All the rest have thirty-one
Excepting February alone,
Which has twenty-eight days clear,
But twenty-nine each Leap Year.

<html>
<head>
<script type="text/javascript">
function showDate()
{
var now = new Date()
var month = now.getMonth()+1
var date = now.getDate()
month = (month < 10)? "0" + month : month
date = (date < 10)? "0" + date : date
document.form1.datefield.value = month + '/' + date + '/' +
now.getFullYear()
}
function calcDate()
{
var montharry = new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
with (document.form1)
{
var month = datefield.value.substr(0,2)
var day = datefield.value.substr(3,2)
var year = datefield.value.substr(6)
}
alert(new Date(day + montharry[month-1] + year ))
}
</script>
</head>
<body onload="showDate()">
<form name="form1" action="">
Date:
<input type="text" id="datefield" size="10" />
<input type="button" value="Check" onclick="calcDate()" />
</form>
</body>
</html>
 
L

Loa

Thank you,
I'm a bit tired tonight, and a busy day tomorrow, but I'll play with it
tomorrow night or next.
The "Thirty days hath September..." brings back some days.
I first learned that in about 4th grade... which is over 50 yrs ago.
Sometimes it's fun to relive the past... so thanks for this too.
LOA

Trevor L. said:
Loa said:
How do I create a form field that defaults to current date using
format mm/dd/yyyy?
Would also like to be able to change the date if necessary and would
like to have it validated to correct format mm/dd/yyyy
Any info will be greatly appreciated

Here is some code which puts today's date in a form fleld in format
mm/dd/yyyy

Changing the date and clicking on "Check" will give a rudimentary date
check.
It will either display the full UTC date or NaN.
It will throw out days or months without leading zeroes.
But it will also accept 01/32/2006 as 1 Feb 2006.
and 01/118/2006 as 11 Jan 2006 (but thows out 01/70/2006)
For better date checkers, see other posts here, especially those by Dr John
Stockton.

Or you could write one yourself.
Just code this into JavaScript :)
Thirty days hath September,
April June and November.
All the rest have thirty-one
Excepting February alone,
Which has twenty-eight days clear,
But twenty-nine each Leap Year.

<html>
<head>
<script type="text/javascript">
function showDate()
{
var now = new Date()
var month = now.getMonth()+1
var date = now.getDate()
month = (month < 10)? "0" + month : month
date = (date < 10)? "0" + date : date
document.form1.datefield.value = month + '/' + date + '/' +
now.getFullYear()
}
function calcDate()
{
var montharry = new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
with (document.form1)
{
var month = datefield.value.substr(0,2)
var day = datefield.value.substr(3,2)
var year = datefield.value.substr(6)
}
alert(new Date(day + montharry[month-1] + year ))
}
</script>
</head>
<body onload="showDate()">
<form name="form1" action="">
Date:
<input type="text" id="datefield" size="10" />
<input type="button" value="Check" onclick="calcDate()" />
</form>
</body>
</html>

--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
T

Trevor L.

Loa said:
Thank you,
I'm a bit tired tonight, and a busy day tomorrow, but I'll play with
it tomorrow night or next.
The "Thirty days hath September..." brings back some days.
I first learned that in about 4th grade... which is over 50 yrs ago.
Sometimes it's fun to relive the past... so thanks for this too.
LOA

Have fun.

Hmm!!
4th grade + 50 years.
I figure I was in 4th class (as we call it here in Australia, or did when I
was in it) in 1950
That makes you younger than me, depending on how much over 50 years
 
L

Loa

Looks like you got me by one or two.
Feb 42 for me.
But a "looker" will make me think it was Feb 62!

Trevor L. said:
Loa said:
Thank you,
I'm a bit tired tonight, and a busy day tomorrow, but I'll play with
it tomorrow night or next.
The "Thirty days hath September..." brings back some days.
I first learned that in about 4th grade... which is over 50 yrs ago.
Sometimes it's fun to relive the past... so thanks for this too.
LOA

Have fun.

Hmm!!
4th grade + 50 years.
I figure I was in 4th class (as we call it here in Australia, or did when I
was in it) in 1950
That makes you younger than me, depending on how much over 50 years
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
L

Loa

Wait a minute, this "Date format" was supposed to be referring to FP code...
Oh well, guess that's what happens when 50+

Trevor L. said:
Loa said:
Thank you,
I'm a bit tired tonight, and a busy day tomorrow, but I'll play with
it tomorrow night or next.
The "Thirty days hath September..." brings back some days.
I first learned that in about 4th grade... which is over 50 yrs ago.
Sometimes it's fun to relive the past... so thanks for this too.
LOA

Have fun.

Hmm!!
4th grade + 50 years.
I figure I was in 4th class (as we call it here in Australia, or did when I
was in it) in 1950
That makes you younger than me, depending on how much over 50 years
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
L

Loa

Trevor,
Decided to try it tonight... worked great.
I can do a little modifying and don't need the test.
I can proof read the entry and since it appears to use current date which is
what I actually need 90% of time, should be just fine.
I was just looking for a shortcut to save time in my data entry and that's
precisely what you gave me.
Thanks again
LOA

Trevor L. said:
Loa said:
Thank you,
I'm a bit tired tonight, and a busy day tomorrow, but I'll play with
it tomorrow night or next.
The "Thirty days hath September..." brings back some days.
I first learned that in about 4th grade... which is over 50 yrs ago.
Sometimes it's fun to relive the past... so thanks for this too.
LOA

Have fun.

Hmm!!
4th grade + 50 years.
I figure I was in 4th class (as we call it here in Australia, or did when I
was in it) in 1950
That makes you younger than me, depending on how much over 50 years
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top