Date and Time Storage

  • PAB202
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Philadelphia

Post 3+ Months Ago

I'm making a page for the company I work for that will essentially allow our clients to fill out a form to make changes to the services that we provide them with. This page is in ASP format and the output is actually sent in an email to another department for input into our system. I've been having trouble being able to include the date and time of the completion of the form into the actual email text that is outputted to the other department for record purposes. If anyone has an easy way of doing this I'd really appreciate the help. Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Welcome to Ozzu PAB202 :D

The first code that gets run in the ASP page that the form is submitted to should Dim a variable & assign the date & time to that variable like so,
Code: [ Select ]
Dim whenSubmitted, anyOtherVariables
whenSubmitted = FormatDateTime(NOW)
  1. Dim whenSubmitted, anyOtherVariables
  2. whenSubmitted = FormatDateTime(NOW)

That will insure that the first thing that happens when the form gets submitted is checking what time at the server submission happened & holding the string returned (ex. 1/5/2004 12:34 am) into a variable that can be used in the output.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Probably something along these lines:

Code: [ Select ]
Dim sMsg as String
sMsg= "Feedback has been sent to you." & vbcrlf & "The results are as follows:" & vbcrlf
sMsg+="Title : " & frmTitle.text & vbcrlf
sMsg+="Email : " & frmEmail.text & vbcrlf
sMsg+="Feedback : " & frmFeedback.text & vbcrlf
sMsg+="Time Entered : " & DateTime.Now()
  1. Dim sMsg as String
  2. sMsg= "Feedback has been sent to you." & vbcrlf & "The results are as follows:" & vbcrlf
  3. sMsg+="Title : " & frmTitle.text & vbcrlf
  4. sMsg+="Email : " & frmEmail.text & vbcrlf
  5. sMsg+="Feedback : " & frmFeedback.text & vbcrlf
  6. sMsg+="Time Entered : " & DateTime.Now()


Got that from here:
http://www.aspnet101.com/aspnet101/pfTu ... aspx?id=36
  • PAB202
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Philadelphia

Post 3+ Months Ago

Ok I think that I might have asked the question wrong because I'm not really familiar with that code...in the page that I have it is saved as an ".asp" file but the actual code inside of the program starts with a html tag and also ends with one. Inside the file are various input commands as well as a small JavaScript command in the beginning. Basically I think what I'm asking is can I get a field to come up with the date and time that a person submits the form (almost like an [OnClick] kind of function)? Below is an example of the tag containing the submit button I'd like to have the date and time field come from when clicked to be submitted.

First...
Code: [ Select ]
<form method=post action="benefitsupdate.asp">

Then later...
Code: [ Select ]
<div align="center">
  <input type="submit" VALUE="Submit" name="Send">
  <input type="reset" VALUE="Reset">
  <!-- End form.htm -->
</div>
  1. <div align="center">
  2.   <input type="submit" VALUE="Submit" name="Send">
  3.   <input type="reset" VALUE="Reset">
  4.   <!-- End form.htm -->
  5. </div>


Any help appreciated. Let me know if what I'm talking about makes sense or is even possible. Thanks.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Well, then taking Joebert's suggestion, I think you'd look at doing something like this:
Code: [ Select ]
<form method=post action="benefitsupdate.asp">

<% Dim whenSubmitted as DateTime
whenSubmitted = FormatDateTime(NOW) %>

<div align="center">
  <input type="hidden"> VALUE="whenSubmitted" name="TimeStamp">
  <input type="submit" VALUE="Submit" name="Send">
  <input type="reset" VALUE="Reset">
  <!-- End form.htm -->
</div>

</form>

FormatDateTime(now) gets the time as Joebert described and turns it into the variable whenSubmitted which is used in the hidden formfield.
  1. <form method=post action="benefitsupdate.asp">
  2. <% Dim whenSubmitted as DateTime
  3. whenSubmitted = FormatDateTime(NOW) %>
  4. <div align="center">
  5.   <input type="hidden"> VALUE="whenSubmitted" name="TimeStamp">
  6.   <input type="submit" VALUE="Submit" name="Send">
  7.   <input type="reset" VALUE="Reset">
  8.   <!-- End form.htm -->
  9. </div>
  10. </form>
  11. FormatDateTime(now) gets the time as Joebert described and turns it into the variable whenSubmitted which is used in the hidden formfield.
  • PAB202
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Philadelphia

Post 3+ Months Ago

Ok that is awesome...I got it to output but instead of actually saying the date and time that it was submitted it actually says "whenSubmitted" in the field. What else should I try??
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Hmmm...Sorry -- I'm still learning ASP and not very good at it yet. I know I have the right idea, but actually doing it sometimes bogs me up. Try this for the hidden field:

Code: [ Select ]
<input type="hidden"> VALUE="<%whenSubmitted%>" name="TimeStamp">
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

PAB202 wrote:
First...
Code: [ Select ]
<form method=post action="benefitsupdate.asp">

Then later...
Code: [ Select ]
<div align="center">
  <input type="submit" VALUE="Submit" name="Send">
  <input type="reset" VALUE="Reset">
  <!-- End form.htm -->
</div>
  1. <div align="center">
  2.   <input type="submit" VALUE="Submit" name="Send">
  3.   <input type="reset" VALUE="Reset">
  4.   <!-- End form.htm -->
  5. </div>


What is the filename of the page that that is in ?
Is it benefitsupdate.asp ?

If it's not, to get the date & time when the form is submitted you are going to have to use the variable I explained earlier in benefitsupdate.asp since that page is the first to know when a the form is submitted.

If that is part of benefitsupdate.asp your going to have to make sure that time is only checked if the mode the page is in (showing form, processing content that form posted to itself) is processing posted data or else you'll get the time that the form was first requested.

You could use VB/Javascript to write the time to a hidden field of the form right before it is submitted but then you get the time as it is on the clients computer. Not all that usefull if you have people submitting the form from different timezones :wink:

btw, ATNO to write data in the middle of the page you need to use an = sign :wink:
Code: [ Select ]
<%= variable %>

which could actually be
Code: [ Select ]
<%= FormatDateTime(NOW) %>
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

So now you have me wanting to learn. So what you are saying to get the actual server time, skip the asp stuff for the form and the hidden field and just submit the form.

Then in benefitsupdate.asp drop this code:
Code: [ Select ]
<% Dim whenSubmitted as DateTime
whenSubmitted = FormatDateTime(NOW) %>
  1. <% Dim whenSubmitted as DateTime
  2. whenSubmitted = FormatDateTime(NOW) %>


Then how would you code that to be included in the email?
  • PAB202
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Philadelphia

Post 3+ Months Ago

The name of the file is "healthbenefits.asp." I put in the expression that you talked about earlier into the "benefitsupdate.asp" code but it still seems to put out "whenSubmitted" in the field box in the email. Any other ideas??
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I would have to see the contents of benefitsupdate.asp to give a full answer, but it should look somthing like this,
Code: [ Select ]
Dim whenSubmitted, emailObj, eBody
whenSubmitted = FormatDateTime(Now)
Set emailObj = Server.CreateObject("CDONTS.NewMail")
'Set the e-mail body format (0=HTML 1=Text)
emailObj.BodyFormat = 0
'Alot of theese
eBody = eBody & Request.Form("formFieldX")
......
'Here's where I'd add the date & time
eBody = eBody & "<br/>Submitted: " & whenSubmitted
'since you should only set an attribute of the email obj once
emailObj.body = eBody
  1. Dim whenSubmitted, emailObj, eBody
  2. whenSubmitted = FormatDateTime(Now)
  3. Set emailObj = Server.CreateObject("CDONTS.NewMail")
  4. 'Set the e-mail body format (0=HTML 1=Text)
  5. emailObj.BodyFormat = 0
  6. 'Alot of theese
  7. eBody = eBody & Request.Form("formFieldX")
  8. ......
  9. 'Here's where I'd add the date & time
  10. eBody = eBody & "<br/>Submitted: " & whenSubmitted
  11. 'since you should only set an attribute of the email obj once
  12. emailObj.body = eBody

Note that the br/ is assuming that bodyFormat is set to HTML(0) & should be replaced with, & vbcrlf & "Submitted: " & whenSubmitted If bodyFormat is set to textOnly(1) turning
Code: [ Select ]
eBody = eBody & "<br/>Submitted: " & whenSubmitted

into,
Code: [ Select ]
eBody = eBody & vbcrlf & "Submitted: " & whenSubmitted
  • PAB202
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Philadelphia

Post 3+ Months Ago

It's difficult to follow everything that's going on in the pages that I'm modifying because my brother (a computer programmer not unlike you guys) is actually the author of the pages and I'm basically trying to make small changes using the primitive scripting that I learned in high school. :shock:

Nonetheless you guys have been a great help and I think that I have the ideas I need to put it all together. Thanks again for your help. :D
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I have picked up some annomalies when usinh HTML e-mails with ASP.

You should insert vbCrLf to break the string, even if you using html email. For some reason if the string gets to long the HTML is not parsed correctly.

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 108 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.