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

Grabbing the current date and time 1

Status
Not open for further replies.

victora

Programmer
Feb 11, 2002
118
US
Hello everybody:
My scenario: DWMX2004, MSSQL Server, ASP.
I'm trying to get a feedback/comment from our doctors. I have a prov_comment.asp where they can enter their comment and I also have a table that contains User_id, Comment and the current date/time.

I like to let them enter just their comment and I will grab the User_id and datetime when they hit the submit button. How can I get the datetime from the system and save it into my table.

Thank you.
 
I guess what chris is trying to say is use the Date and Time functions in ASP when getting the values from your form. Capture the timestamp on the server not from the client.

Your client may be in a different time zone than your server. Even if your clients are within the same geographical area you cannot be 100% sure that they won't change their time settings.

Just grab the information they have submitted and then use an ASP variable that gets assigned the server's date and time and use that value for your tables.


good luck

grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
Thank you guys for your replies. This must be my 2nd or 3rd ASP page so can you tell me where will I insert the Date and time function? I was browsing ASP tutorials online and come accross examples that are current date you display on your pages. How about capturing them and save them into a field called Date_Stamp with a datetime type.

maybe something like: Date_Stamp=now() or
Date_Stamp=Date ???

thanks
 
Why do it on the page at all? If you set the db field as date and give it a default value of Now() then when an entry is added the db will add the required date/time stamp itself.

Cheech

[Peace][Pipe]
 
what CHeech has mentioned is good use of DB to auto-record eg. when the user has created a record...
so u have a choice:
A- use the DB to record the time/date
B- have user enter it (through the hidden field) along with the other info that he.she is entering



B-
by having a field in your form (hidden) whose defult value is <%=Now()%>

just paste this into your page body to display it:

Today's date and time is <%=Now()%>


more info on date formats etc.


All the best!

:--------------------------------------------------------------------------:
fugitive.gif

ok,ok...I did shoot the deputy but he told me he was the sheriff!
:--------------------------------------------------------------------------:
 
I agree with everyone here. In SQL, set your default value to be 'getdate()' and you won't have to worry about them entering dates-especially in the wrong format! Lebisol, thanks for that code though, I was able to apply it elsewhere.

Al

"Be quiet Brain, or I'll stab you with a Q-tip!" (Homer Simpson)
 
excellent!
bendall, glad that snip worked out for you.
All the best!

:--------------------------------------------------------------------------:
fugitive.gif

All around in my home town,
They tryin' to track me down...
 
here is another snip that has to do with time...

you can use this concept to allow users to eg.
only be able to edit record within 5 minutes of record creation.
it is a simmilar idea of "page timeout" but wihtout the nasty message and users possibly hitting Refresh button and re-submitting the page...
anyhow...just some extra info...
All the best!

:--------------------------------------------------------------------------:
fugitive.gif

All around in my home town,
They tryin' to track me down...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top