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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Date

Status
Not open for further replies.

megasuperman

Programmer
Aug 20, 2001
21
US
I need to be able to add the current date to a record in an SQL database

I have a textbox that currently allows user input of the date but I need it automated so no one types in the wrong date (accidental or intentional)

So I have a Text Box that I want to update with the current date in shortdate format

i.e. 8-26-01 or 8-26-2001 or 08-26-2001 or 8/26/01 or 8/26/2001 or 08/26/2001

Any of the previous would work
date only not time

Thanx
 
You are just going to have to write a bit of code that does the old "30 days hath September" thing on whatever they enter.

Not a particularly hard algorithm to construct...in fact now that I think about it...I think I may have something.

(browses hard drive)

here is a JS function you can use as a start. If you wanted to get REAL flash, you could check to see if this year is a leap year before deciding what to do with February...

//===========================================================
// validate date
//===========================================================

function validateDate(field) {
var input = parseInt(field.value, 10)
if (isEmpty(input)) {
alert("Be sure to enter a date value.")
select(field)
return false
} else {
if (isNaN(input)) {
alert("Entries must be numbers only.")
select(field)
return false
} else {
var monthField = document.addUserDetails.month
if (!validateMonth(monthField, true)) return false
var monthVal = parseInt(monthField.value, 10)
var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31)
var top = monthMax[monthVal]
if (!inRange(input,1,top)) {
alert("Enter a number between 1 and " + top + ".")
select(field)
return false
}
}
}
calcDate()
return true
}

function validateMonth(field, bypassUpdate) {
var input = parseInt(field.value, 10)
if (isEmpty(input)) {
alert("Be sure to enter a month value.")
select(field)
return false
} else {
if (isNaN(input)) {
alert("Entries must be numbers only.")
select(field)
return false
} else {
if (!inRange(input,1,12)) {
alert("Enter a number between 1 (January) and 12 (December).")
select(field)
return false
}
}
}
if (!bypassUpdate) {
calcDate()
}
return true
}

function validateYear(field) {
var input = parseInt(field.value, 10)
if (isEmpty(input)) {
alert("Be sure to enter a month value.")
select(field)
return false
} else {
if (isNaN(input)) {
alert("Entries must be numbers only.")
select(field)
return false
} else {
if (!inRange(input,1900,2005)) {
alert("Enter a number between 1900 and 2005.")
select(field)
return false
}
}
}
calcDate()
return true
}

=====================

Good luck
Steve Davis
hey.you@hahaha.com.au
 
If for some reason date() doesn't work. Try now().
-Ovatvvon :-Q
 
thanx all

I did use date I just had to use it different than I was trying at first got frustrated and posted


thanx

it was having a problem because it was a hidden field

so I was getting type mismatch and thought I was doing something wrong

I just had to define that the code was running at the server instead of the client so that it would be edited before it was hidden


I used
<SCRIPT LANGUAGE=VBScript RUNAT=&quot;Server&quot;>
OrderDate.value = Date()
</SCRIPT>

worked great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top