Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I seperate date from time in appointment file sent from asp?

Posted on 2011-03-23
6
Medium Priority
?
306 Views
Last Modified: 2012-05-11
I have a code (attached) that sends an appointment...I need to know how to make it show the start time and end time properly.  Right now it's adding an all day time the day before.

As you can see from the code, it pulls the date from the form field, but I need to have it seperate it from the time (another field).  How do I do that?

Thanks!
Kevin
Dim fso, file, filename, tmpName, startDate, endDate, uniqueID
Dim yourEmail, smtpServer
 
yourEmail = "me@company.com"
smtpServer = "mail.company.com"
 
Set fso = Server.CreateObject("Scripting.FileSystemObject")
 
' Get a temporary filename on the web server where we can write the iCalendar
' format file.
tmpName = fso.GetTempName() & ".ics"
filename = Server.MapPath(".") & "\" & tmpName
 
' Get the start and end dates of the event (GMT).
startDate = request.form("startdate")
endDate = request.form("startdate")
 
' Get a unique ID to assign to the calendar event.
uniqueID = FormatDateTime(Now()) & "-" & tmpName & "-@" &_
   Request.ServerVariables("SERVER_NAME")
 
Set file = fso.CreateTextFile(filename)
 
' Write the iCalendar file to the file system.
file.WriteLine "BEGIN:VCALENDAR"
file.WriteLine "PRODID:-//ASP iCalendar Test//My ASP App V1.0//EN"
file.WriteLine "VERSION:2.0"
file.WriteLine "METHOD:REQUEST"
file.WriteLine "BEGIN:VEVENT"
file.WriteLine "ORGANIZER:MAILTO:onboarding@msssolutions.com"
file.WriteLine "DTSTART:" & FormatDateTime(startDate)
file.WriteLine "DTEND:" & FormatDateTime(endDate)
file.WriteLine "LOCATION:At the office"
file.WriteLine "TRANSP:OPAQUE"
file.WriteLine "SEQUENCE:0"
file.WriteLine "UID:" & uniqueID
file.WriteLine "DTSTAMP:" & FormatDateTime(Now())
file.WriteLine "DESCRIPTION:My calendar event test."
file.WriteLine "SUMMARY:Valentine's Day Party"
file.WriteLine "PRIORITY:5"
file.WriteLine "CLASS:PUBLIC"
file.WriteLine "BEGIN:VALARM"
file.WriteLine "TRIGGER:-PT15M"
file.WriteLine "ACTION:DISPLAY"
file.WriteLine "END:VALARM"
file.WriteLine "END:VEVENT"
file.WriteLine "END:VCALENDAR"
 
file.Close()
 
' Send the iCalendar file as an email attachment.
Dim mail
Set mail = CreateObject("CDO.Message")
 
' Configure to use an external mail server (2), supply its domain name or IP
' address (your.smtp.server), and tell it which port to use (usally 25).
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
mail.Configuration.Fields.Update()
 
' Set up the email message body.
mail.Subject = "New Hire " & request.form("namelast") & request.form("namefirst")
mail.From = "onboarding@msssolutions.com"
mail.To = yourEmail
mail.TextBody = "A new hire has been posted.  Please go to http://fs04sql/newhire/allnew.asp for more information." & chr(10) & chr(10) & "Name: " & request.form("namelast") & " " & request.form("namefirst") & chr(10) & "Start Date: " & request.form("startdate") & chr(10) & "Position: " & request.form("position") & chr(10) & "Division: " & request.form("division")
 
' Prepare the file attachment (the iCalendar file).
Dim att
Set att = mail.AddAttachment(filename)
att.ContentClass = "urn:content-classes:calendarmessage"
att.Fields.Item("urn:schemas:mailheader:content-type") = "text/calendar; method=REQUEST; name=""invite.ics"""
att.Fields.Item("urn:schemas:mailheader:content-disposition") = ""
att.Fields.Item("urn:schemas:mailheader:content-transfer-encoding") = "8bit"
att.Fields.Update()
 
' Set the content type of the email and send it.
mail.Fields.Item("urn:schemas:mailheader:content-type") = "multipart/alternative"
mail.Fields.Update()
mail.Send()
 
' Cleanup the file.
fso.DeleteFile filename, True
 
Set mail = Nothing
Set file = Nothing
Set fso = Nothing
 
' Utility function for date/time formatting.
Public Function FormatDateTime(dateTime)
   FormatDateTime = _
      Year(dateTime) &_
      Right("0" & Month(dateTime), 2) &_
      Right("0" & Day(dateTime), 2) &_
      "T" &_
      Right("0" & Hour(dateTime), 2) &_
      Right("0" & Minute(dateTime), 2) &_
      Right("0" & Second(dateTime), 2) &_
      "Z"
End Function

Open in new window

0
Comment
Question by:Kevin Smith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
AlexPace earned 2000 total points
ID: 35202344
Well you shouldnt write your own function with the same name as the ASP funciton you'll actually want to use.

startDate = request.form("startdate")
If IsDate(startDate) Then
  startTime = FormatDateTime(startDate, 3)
End If

endDate = request.form("startdate")
if IsDate(endDate) Then
  startTime = FormatDateTime(endDate, 3)
End If
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 35202362
i would remove your FormatDateTime function and use the built in one:

http://www.w3schools.com/vbScript/func_formatdatetime.asp

That should give you the different formats you need.
0
 

Author Comment

by:Kevin Smith
ID: 35206240
good point Alex...

BigD...so I remove the innards and just stick with

' Utility function for date/time formatting.
Public Function FormatDateTime(dateTime)
  End Function

??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Kevin Smith
ID: 35206256
And how would I default the end time to 1 hour after?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 35206569
asp has a built in function called FormatDateTime, so if you create one yourself, it'll over-ride it. I suggest removing it totally from your code or commenting it out. Then you can use Alex's syntax for what you need.

to add an hour to a time, you'll want to use the DateAdd function:

endTime = "12:30:00 am"
endTime = DateAdd( "h", 1, endTime )
0
 

Author Closing Comment

by:Kevin Smith
ID: 35345215
thanks to you as well bigdaddy
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question