|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP Date Help Needed
I will try to explain this problem the best I can. I use a credit card processor that requires a date to be submitted when sending the customer to the payment form. I have some code that was given to me to get the date and then put it in the form, so the customer doesn't have to. The processor requires the date but not the hour. The issue I have is the time difference between my host and the payment processor's server. There is a 3 hour difference, so this causes an error from 12 am to 3 am, in those 3 hours, the processor's server thinks it is the next day already and my host sends the date as the previous day. I will paste all of the code that I have and would really appreciate any help I can get. I need to add 3 hours to the date that is sent, but I only need it to send it in the format in the code of just the year, month and day.
This is the code below that works, but fails during the 12 am to 3 am hours. Any help that can be offered would be greatly appreciated. Thanks. Code:
<%
Function FormatMediumDate(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
strYYYY = CStr(DatePart("yyyy", DateValue))
strMM = CStr(DatePart("m", DateValue))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", DateValue))
If Len(strDD) = 1 Then strDD = "0" & strDD
FormatMediumDate = strYYYY & strMM & strDD
End Function
%>
Monthly charge of $1.00<br>
<form action="https://www.ccprocessor.com" method="post">
<input type="hidden" name="mode" value="fullpay">
<input type="hidden" name="txntype" value="sale">
<input type="hidden" name="submode" value="periodic">
<input type="hidden" name="periodicity" value="m1">
<input type="hidden" name="installments" value="-1">
<input type="hidden" name="threshold" value="2">
<input type="hidden" name="storename" value="123456">
<input type="hidden" name="chargetotal" value="1.00">
<input type="hidden" name="startdate" value="<% = FormatMediumDate(Date()) %>">
<input type="submit" value="Continue to secure Payment form" >
</form>
|
|
#2
|
||||
|
||||
|
-->Thread moved to ASP Development
you can do this by adding 3 hours to the datevalue before splitting M/D/Y ... Code:
Function FormatMediumDate(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
Dim strDate
strDate = DateAdd("h",3,DateValue)
strYYYY = CStr(DatePart("yyyy", strDate))
strMM = CStr(DatePart("m", strDate))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", strDate))
If Len(strDD) = 1 Then strDD = "0" & strDD
FormatMediumDate = strYYYY & strMM & strDD
End Function
__________________
Come JOIN the party!!! Quote of the Month: Pretension: The downside of being better than everyone else is that people tend to assume you're pretentious. Questions to Ponder: You can be overwhelmed and underwhelmed, but why can't you be simply whelmed? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 |
|
#3
|
|||
|
|||
|
Thanks. Someone also replied to me on another forum saying that using this would be more efficient.
Code:
<%
Function DateAtCCProcessor( )
Dim today
today = DATEADD( "h", 3, Now() ) ' add 3 hours to get to CC processor time
DateAtCCProcessor = Year(today) * 10000 + Month(today) * 100 + Day(today)
End Function
%>
and then this in the form Code:
<input type="hidden" name="startdate" value="<%=DateAtCCProcessor( )%>"> If this method doesn't work I will use yours. Thank you so much for your help. Aslo, if anyone sees any reason why the new code I got from the other forum might cause a problem, please let me know. |
|
#4
|
||||
|
||||
|
I cant see any reason why the code from the other forum wouldn't work and I agree that it is more efficient.
I've never seen that technique for formatting the date before but it is doing exactly the same as your original code. For anyone who is wondering how it works: the original function breaks the date down into its component parts, padding the day and month values out to two digits and concatenating them back together in a different order: Code:
Function FormatMediumDate(DateValue)
Dim strYYYY
Dim strMM
Dim strDD
Dim strDate
strDate = DateAdd("h",3,DateValue)
strYYYY = CStr(DatePart("yyyy", strDate))
strMM = CStr(DatePart("m", strDate))
If Len(strMM) = 1 Then strMM = "0" & strMM
strDD = CStr(DatePart("d", strDate))
If Len(strDD) = 1 Then strDD = "0" & strDD
FormatMediumDate = strYYYY & strMM & strDD
End Function
The new function does exactly the same job but doesnt need to worry about padding the day/month values out to two digits because it is multiplying the value by a set number meaning that the day/month/year will always be in the correct position: Code:
Function DateAtCCProcessor( )
Dim today
today = DATEADD( "h", 3,Now() ) ' add 3 hours to get to CC processor time
DateAtCCProcessor = Year(today) * 10000 + Month(today) * 100 + Day(today)
End Function
For the date 31/12/2009 the function would convert it to: (2009 * 10000) + (12 * 100) + 31 = 20090000 + 1200 + 31 = 20091231 Very clever!! |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > ASP Date Help Needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|