Date()

K

Keith

If I use <%Date()%> <%Time()%> to insert the current date and time into
hidden fields on my page which I then insert into a database via a web form,
how accurate are the dates?

Are these (as I suspect) the data and time of the local/remote machine at
the time the page was loaded?

I am trying to find out if this is the case, because if a user opens the
form and keeps it open for 10 minutes before submitting it, then the date
and time recorded this way will be 10 minutes old at the time of submission.

Is this correct?

And if so, is there a way around it where the date and time can be inserted
into hidden fields at the time of submit?

Thanks
 
B

Bob Barrows [MVP]

Keith said:
If I use <%Date()%> <%Time()%> to insert the current date and time
into hidden fields on my page which I then insert into a database via
a web form, how accurate are the dates?

Depends on how you define "accurate"
Are these (as I suspect) the data and time of the local/remote
machine at the time the page was loaded?
Yes


I am trying to find out if this is the case, because if a user opens
the form and keeps it open for 10 minutes before submitting it, then
the date and time recorded this way will be 10 minutes old at the
time of submission.

Is this correct?
Yes


And if so, is there a way around it where the date and time can be
inserted into hidden fields at the time of submit?

a - use client-side code to refresh the values in the form's onsubmit event
(this is offtopic for this list - if you need help with this ask in one of
the scripting or dhtml newsgroups

b - stop using the hidden textboxes. Use code in the page to which the form
is being submitted to calculate the current time and date.

Bob Barrows
 
C

Curt_C [MVP]

hare your asp use the Date() and Time() when it's posted/saved, not when
it's rendered to the screen.
Also, those are Server based values, not client.
 
D

Dave Anderson

Keith said:
And if so, is there a way around it where the date and time can be
inserted into hidden fields at the time of submit?

Why not just let the database determine the time when you insert? In SQL
Server, for example, you can use GETDATE() as the default value for a
DATETIME field.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top