0

I need to create the date and time of extraction in the following format.

extractDate='2011-10-18T12:00:00.000000'

What is the best way, using vbscript / asp3 to do this? I was just thinking of hard-coding the end portion of .000000 since this is not a horse race LOL

Thanks.

So Far I am starting with something like;

xmlDateTime = FormatDateTime(Now(),0)
xmlDateTime = Replace(xmlDateTime, " PM", "")
xmlDateTime = Replace(xmlDateTime, " AM", "")
Response.Write xmlDateTime & "<br>"

UPDATE:

My potential solution:

xmlDateTime = FormatDateTime(Now(),0)
xmlDateTime = Replace(xmlDateTime, " PM", "")
xmlDateTime = Replace(xmlDateTime, " AM", "")
Response.Write xmlDateTime & "<br>"
splitDateTime = Split(xmlDateTime, " ")

xmlDate = splitDateTime(0)
xmlTime = splitDateTime(1)

strYear = DatePart("yyyy",xmlDate)
strMonth = DatePart("m",xmlDate)
strDay = DatePart("d",xmlDate)


Response.Write strYear & "<br>"
Response.Write strMonth & "<br>"
Response.Write strDay & "<br>"

xmlDateTime = strYear & "-" & strMonth & "-" & strDay & "T" & xmlTime & ".000000"
Response.write xmlDateTime & "<br>"
2
  • 1
    Simply removing "AM" and "PM" from the string will give you an incorrect time string the second half of the day. Date formats with AM/PM use a 12-hour clock whereas you need a 24-hour clock. Commented Oct 4, 2012 at 18:22
  • TY - I am going to go with the best answer below too. THanks all. Commented Oct 4, 2012 at 18:28

1 Answer 1

3

You need to construct the date string manually.

Function dd(str)
  dd = Right("0" & str, 2)
End Function

d = Now
extractDate = Year(d) & "-" & dd(Month(d)) & "-" & dd(Day(d)) & "T" _
  & dd(Hour(d)) & ":" & dd(Minute(d)) & ":" & dd(Second(d)) & ".000000"
Sign up to request clarification or add additional context in comments.

2 Comments

So awesome too! Does a good programmer always need to think in terms of code separation no matter what the language?
It helps avoiding maintenance headaches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.